使用虚假可调焦复选框,仍然可以防止listview点击
问题描述:
你好,我已经阅读了很多有关Android中的CheckBox/ListView问题。所以我尝试了很多问题。使用虚假可调焦复选框,仍然可以防止listview点击
开始我的行布局看起来像这样。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
</LinearLayout>
于是我尝试添加这对我的ListActivity
ListView listview = getListView();
listview.setItemsCanFocus(false);
然后试图与onListItemClick断点,仍然没有命中(行进路线调试)运行它。
这是我的onListItemClick,以防您想要查看。
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// let's find the checkbox we're on.
CheckBox targetCheckBox = (CheckBox) l.findViewById(R.id.check);
// ok update the database with the new data.
mDbHelper.updateNote(id, !targetCheckBox.isChecked());
// update the list now.
showList();
}
如果我再更改复选框CheckTextView,它的工作,但是我从来没有这样做之前,我宁愿弄清楚到底是什么错在这里是当其他人已经解决了这一点。有什么想法吗?
答
显然我错过
android:clickable="false"
除了复选框下
android:focusable="false"
正确添加两条线,使onListItemClick火灾。
一旦你调用了'onListItemClick()',你的代码就被破坏了。你不要在'ListView'上调用'findViewById()'来获得你的'CheckBox',你可以在'View''上使用'findViewById()','View'就是'View'行。 – CommonsWare 2010-06-25 00:44:16
啊,谢谢你。然而,我在该行的断点甚至没有被触及,所以我没有机会调试该代码(除了它被checktextview打中)。 – Kinglink 2010-06-25 20:24:20