为什么滚动后ListView项变得不可单击 [英] Why ListView Items becomes not clickable after scroll
问题描述
我用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项变得不可单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!