3

I created a custom ListView with ImageView and TextViews and every thing worked fine until i tried to implement onItemClick, which for the time being only shows a Toast.

The problem occurs when i scroll down my ListView: it won't receive any clicks.

Funny thing is that when i use the keyboard to move from item to item it works and when i hit enter the Toast is shown

This is the code i used for 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();
}
ColdFire
  • 6,764
  • 6
  • 35
  • 51
  • 2
    Please post all of the code related to your ListView. The adapter you are using to load it, and the onClickListener you are using to get your click callbacks. Without this code it is unlikely anyone will be able to help. – FoamyGuy Aug 17 '11 at 13:18
  • it's becouse of political influence ... in other words ... it's not possible to answer this question without some portion of code (both java and xml) – Selvin Aug 17 '11 at 13:18

1 Answers1

10

i think i solved this problem: after going through some documentation i figured out that this problem comes from the textviews and imagesview on top of each row which block the onitemselected listener. so i tryed to refresh the list view after scroll and it worked just fine. here's what i did hoping it 'll help those who may come accross 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) {}
    });
ColdFire
  • 6,764
  • 6
  • 35
  • 51
  • Thanks a lot, it was a weird issue and u helped me out. :) – Jay Mayu Sep 23 '11 at 13:09
  • I had a very weird issue too where the GridView became unclickable if I came back to the GridView activity from another Activity via a Back button. This only started happening on Honeycomb. Putting the invalidateViews() call in onResume() seems to fix the problem. – Artem Russakovskii Nov 01 '11 at 00:25
  • I'm facing the same issue. After scrolling the buttons in listview do not work. The button state changes to selected and and remains like that and the button onclick listener is not called. – Abdullah Umer Feb 24 '19 at 07:31
  • Thanks a lot, you saved my day! Solved similiar issue with expandable list view. – x.iva Jan 25 '23 at 13:18