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.ma开发者_开发百科keText(this, clickedItem.getName()+", "+clickedItem.getCost(), 1000).show();
}
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) {}
});
精彩评论