使用具有false focusable的复选框仍然可以防止listview点击

Kin*_*ink 4 java checkbox android listview

您好我已经阅读了很多关于Android中CheckBox/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>
Run Code Online (Sandbox Code Playgroud)

那么我尝试将其添加到我的ListActivity中

 ListView listview = getListView();
 listview.setItemsCanFocus(false);
Run Code Online (Sandbox Code Playgroud)

然后尝试在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();

    }
Run Code Online (Sandbox Code Playgroud)

如果我然后将Checkbox更改为CheckTextView,它确实有效,但我以前从未这样做过,而且当其他人解决了这个问题时,我宁愿弄清楚这里究竟出了什么问题.有什么想法吗?

Kin*_*ink 13

显然我失踪了

android:clickable="false"
Run Code Online (Sandbox Code Playgroud)

除了复选框之外

android:focusable="false"
Run Code Online (Sandbox Code Playgroud)

添加这两行会使onListItemClick正确触发.