我有一个简单的ListActivity,它使用自定义ListAdapter在列表中生成视图.通常ListAdapter只会用TextViews填充视图,但现在我想在那里放一个按钮.
然而,根据我的理解和经验,在列表项中放置可聚焦视图可以防止在单击列表项时在ListActivity中触发onListItemClick().按钮仍然在列表项中正常运行,但是当按下按钮之外的其他内容时,我希望触发onListItemClick.
我怎样才能做到这一点?
我到处寻找解决方案,但我无法弄清楚如何实现它.我的行OnItemClickListener被禁用了ListView,因为我ImageButton在行布局中有一个接管焦点.我发现了很多问题,但没有一个问题让我到处都是.
我已经检查了这个问题,但我无法真正做到这一点.我只需要一种方法来获取可点击的行,以便我可以检测何时按下一行.长按和聚焦工作正常.
我有一个包含CheckBox的列表项,我希望能够单击CheckBox和列表项本身.不幸的是,两者之间似乎存在某种冲突,因为我只能在注释掉CheckBox时单击该项.我好像记得有办法解决这个问题,但目前我找不到它.谢谢
编辑:这是一个ListFragment,所以没有必要调用setOnItemClickListener.
好的,这是列表项的XML.问题是CheckBox,但我想也可以复制一切.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_survey"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/SimpleListItem">
<TextView
android:id="@+id/survey_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/ListItemTitle" />
<TextView
android:id="@+id/survey_date"
android:layout_below="@id/survey_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/ListItemSubtitle" />
<TextView
android:id="@+id/survey_completed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/survey_title"
android:textColor="@color/accent_1"
android:text="@string/survey_completed"
style="@style/ListItemSubtitle" />
<CheckBox
android:id="@+id/survey_did_not_attend"
android:layout_below="@id/survey_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/survey_did_not_attend"
android:focusable="false"
style="@style/ListItemSubtitle" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)