setOnItemClickListener() 不适用于自定义 ListView @ Android [英] setOnItemClickListener() not working on custom ListView @ Android
问题描述
我通过为每一行扩展 LinearLayout
实现了自定义 ListView
.每一行都有一个小缩略图、一个文本和一个复选框
.list view
部署正确,我可以毫无问题地滚动和浏览它.
I have Implemented a custom ListView
by extending LinearLayout
for every row. Every row has a small thumbnail, a text and a check box
. The list view
is deployed properly and I can scroll and fling through it without any problems.
但是 ListView
似乎根本没有响应 setOnItemClickListener()
,所以我不得不通过在 中设置点击侦听器来找到解决方法getView()
每行内的 Text ,当我尝试重用 adapter
时,这显然会产生问题.有人有解决办法吗?
But The ListView
doesn't seem to respond to the setOnItemClickListener()
at all, So I had to find a workaround by setting click listener in the getView()
of the Text inside every row which is obviously creating problem when I am trying to reuse the adapter
. Does anyone have a solution?
推荐答案
试试这个
对于列表视图,
Try this
For ListView,
final ListView list = (ListView) findViewById(R.id.list);
list.setItemsCanFocus(false);
另外,确保为列表项内的 CheckBox 设置 focusable false
Also, make sure that for CheckBox inside list item set focusable false
android:focusable="false"
android:focusableInTouchMode="false"
这篇关于setOnItemClickListener() 不适用于自定义 ListView @ Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!