为什么滚动后ListView项变得不可单击

编程入门 行业动态 更新时间:2024-10-24 01:48:15
本文介绍了为什么滚动后ListView项变得不可单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我用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项变得不可单击

本文发布于:2023-07-19 08:54:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154912.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   ListView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!