我用ImageView和TextViews创建了一个自定义的ListView,在我尝试实现onItemClick之前,每件事都运行良好,暂时只显示了Toast.
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.
当我向下滚动ListView时会出现问题:它将不会获得任何点击.
The problem occurs when i scroll down my ListView: it won't receive any clicks.
有趣的是,当我使用键盘从一个项目移动到另一个项目时,它会起作用,并且当我按下Enter键时,会显示Toast
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
这是我用于onItemClick侦听器的代码.
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(); }推荐答案
我认为我解决了这个问题:在阅读了一些文档之后,我发现这个问题来自每一行顶部的textviews和imagesviews,它们阻止了onitemselected听众.因此,我尝试在滚动后刷新列表视图,并且效果很好.这就是我希望它能帮助可能遇到此问题的人的地方
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) {} });更多推荐
为什么滚动后ListView项变得不可单击
发布评论