Android ListView 不允许选择器工作,也不允许选择
好吧,我知道这听起来可能像有关 ListView 和 ListActivity 问题的任何其他问题,但这不是,我会发疯的,因为我在过去的一周中一直在搜索所有帖子以找到可能有帮助的解决方案我。已经尝试过通过自定义选择器的ListView项目背景和GetView 与。自定义 CursorAdapter 中的 BindView? 所有其他可能的博客站点...
好吧,问题是,我的 listView 1 不允许选择/触发事件,2. 单击某个项目时不会更改行突出显示。我有一个标准的TestActivity
扩展ListActivity
并且我已经实现了一个自定义TestCursorAdapter扩展SimpleCursorAdapter
现在在我在test_list_view上的XML方面.xml
和第二个 row_view.xml
现在,我按照上面提到的答案并将 selector
实现为 row_selector.xml
。但问题是行不接受任何点击或焦点事件。 是否发生任何事情
@Override
protected void onListItemClick(ListView l, View v , int postion, long idontnow){
Toast.makeText(getApplicationContext(), "Hello World", Toast.LENGTH_SHORT ).show();
}
一部分
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:cacheColorHint="#00000000"
android:focusable="true"
android:listSelector="@color/row_selector"
android:background="@color/Transparent"/>
我实现了一个基本的 toast 来指示selecter.xml 的 test_list_view.xml 部分(基本上是从上述链接之一复制并粘贴)的
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/Transparent" />
<item
android:state_focused="true"
android:state_enabled="false"
android:state_pressed="true"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_enabled="false"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/blue" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@color/blue" />
<item
android:state_focused="true"
android:drawable="@color/green" />
<item
android:state_selected="true"
android:drawable="@color/blue" />
<item
android:drawable="@color/Transparent" />
</selector>
,我遵循了我所知道的所有选项,但仍然没有任何结果。 唯一的主要区别是我没有使用getView
,而是使用bindView
。
任何帮助人员将不胜感激。
提前致谢。
桑吉
Okay I know this may sound like any other issues regarding the ListView and ListActivity issues but this is not, I am going to go crazy as I have in the past week gone on and on searching all post to find any solution to this that may help me. Already tried ListView item background via custom selector and GetView Vs. BindView in a custom CursorAdapter? every other possible blogs sites...
Okay the issue, My listView for one 1 will not allows selection/fire events and 2. will not change the row highlight when an item is clicked. I have a standard TestActivity
extending ListActivity
and I have implemented a Custom TestCursorAdapter extends SimpleCursorAdapter
Now in XML side of things I have on test_list_view.xml
and second one row_view.xml
Now I followed the above mentions answers and implement selector
as row_selector.xml
. But the issue is for one the rows does not accept any click or focus events. I implemented a basic toast to indicate if there is anything happening
@Override
protected void onListItemClick(ListView l, View v , int postion, long idontnow){
Toast.makeText(getApplicationContext(), "Hello World", Toast.LENGTH_SHORT ).show();
}
part of test_list_view.xml
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:cacheColorHint="#00000000"
android:focusable="true"
android:listSelector="@color/row_selector"
android:background="@color/Transparent"/>
part of selector.xml (basically copied and pasted from one of the above mentioned links)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/Transparent" />
<item
android:state_focused="true"
android:state_enabled="false"
android:state_pressed="true"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_enabled="false"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/blue" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@color/blue" />
<item
android:state_focused="true"
android:drawable="@color/green" />
<item
android:state_selected="true"
android:drawable="@color/blue" />
<item
android:drawable="@color/Transparent" />
</selector>
I followed all options that I am aware of and still nothing. The only major difference is guys I am not using getView
instead I am using bindView
.
Any help guys will be highly appreciated.
thanks in advance.
Sanj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您从
ListView
中删除android:focusable="true"
。此外,您可以使用
选择器
作为ListView
中显示的项目的背景颜色。还要确保这些元素没有调用onClick
或onTouch
或类似的东西,并让ListView
处理点击事件。我希望这有助于
编辑:
解决您选择项目使用的问题
I suggest that you remove the
android:focusable="true"
from theListView
.Additionally, you can use the
selector
as the background color of the items that are displayed in theListView
. Also be sure that those elements are not callingonClick
oronTouch
or something like that, and let theListView
handle the click events.I hope this helps
EDIT:
for your problem with selecting the item use
遵循 raukodraug 的建议和帖子
ListView OnItemClickListener 没有响应?
提到的另一个事实是使用
bindView
方法, 我才使用仅当您单击以黄色突出显示的区域和
ImageView
时, 项目单击类型的作品。我应该能够弄清楚这一点,谢谢,已编辑
哦*%# $ 解决了,需要设置RelativeLayouts
Add State from Children = true;
following raukodraug's suggestion and post
ListView OnItemClickListener Not Responding?
Another fact as mentioned use
bindView
method, I usedthe item click kind of works, only if you click on the region marked highlighted in Yellow and the
ImageView
. I should be able to figure this out thanks,Edited
Oh *%#$ Solved it, Needed to set the RelativeLayouts
Add State from Children = true;