Why ListView items become unavailable after scrolling

I created a custom ListView with ImageView and TextViews , and everything worked fine until I tried to implement onItemClick , which so far only shows a toast.

The problem arises when I view my ListView : it will not receive any clicks.

It's funny that when I use the keyboard to move from an element to the element that it works, and when I'm in, type Toast .

This is the code I used for the onItemClick listener.

 @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { RestaurantReservationBean clickedItem = resultArray.get(position); Toast.makeText(this, clickedItem.getName()+", "+clickedItem.getCost(), 1000).show(); } 
+4
source share
1 answer

I think I solved this problem: after going through some documentation, I realized that this problem comes from text views and images at the top of each line, which blocks the onitemselected listener. so I tried updating the list view after scrolling, and it worked just fine. here is what i was hoping this would help those who might run into this problem.

 listView.setOnScrollListener(new OnScrollListener() { public void onScrollStateChanged(AbsListView view, int scrollState) { if ( scrollState == OnScrollListener.SCROLL_STATE_IDLE ) { listView.invalidateViews(); } } @Override public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {} }); 
+10
source

All Articles