为什么 ListView 项目在滚动后变得不可点击
我使用 ImageView
和 TextViews
创建了一个自定义 ListView
,一切都工作正常,直到我尝试实现 onItemClick
,这暂时只显示一个Toast。
当我向下滚动 ListView
时出现问题:它不会收到任何点击。
有趣的是,当我使用键盘从一个项目移动到另一个项目时,它可以工作,当我按 Enter 时,会显示 Toast
这是我用于 onItemClick
侦听器的代码。
@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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我解决了这个问题:在浏览了一些文档之后,我发现这个问题来自于每行顶部的 textviews 和 imagesview ,它们阻止了 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