好吧,我知道这可能听起来像关于ListView和ListActivity问题的任何其他问题,但事实并非如此,我会像过去一周那样疯狂,并在搜索所有帖子以找到任何可能帮助我的解已经试过了 通过自定义选择器ListView项目背景GetView Vs.自定义CursorAdapter中的BindView? 所有其他可能的博客网站。..

好的问题,我的listView为一个1将不允许选择/火灾事件和2。单击项目时不会更改行突出显示。我有一个标准 TestActivity 延伸;延伸 ListActivity 我已经实现了一个自定义 TestCursorAdapter extends SimpleCursorAdapter

现在在XML方面的事情我有 test_list_view.xml 第二个 row_view.xml 现在我按照上面提到的答案和实现 selector 作为 row_selector.xml.但问题是一行不接受任何单击或焦点事件。我实现了一个基本的toast来指示是否有任何事情发生

@Override
protected void onListItemClick(ListView l, View v , int postion, long idontnow){
    Toast.makeText(getApplicationContext(), "Hello World",  Toast.LENGTH_SHORT ).show();
}

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"/>

选择器的一部分。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.

任何帮助的人将不胜感激。

先谢谢你。

桑吉

有帮助吗?

解决方案

我建议你删除 android:focusable="true"ListView.

此外,您可以使用 selector 作为显示在 ListView.还要确保这些元素没有调用 onClickonTouch 或者类似的东西,让 ListView 处理点击事件。

我希望这有助于

编辑:

对于您选择项目使用的问题

lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            yourMethod();
        }
    });

其他提示

遵循raukodraug的建议和帖子 ListView OnItemClickListener没有响应?

另一个事实,如所述使用 bindView 方法,我用

view.setClickable(true);
view.setFocusable(true); 

项目点击类型的工作,只有当你点击标记为黄色突出显示的区域和 ImageView.我应该能够弄清楚这一点谢谢,

enter image description here

编辑

Oh*%#$解决了,需要设置RelativeLayouts Add State from Children = true;

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top