繁体   English   中英

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

[英]Using a checkbox with a false focusable, still prevents listview clicks

您好我已经阅读了很多关于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>

那么我尝试将其添加到我的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();

    }

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

显然我失踪了

android:clickable="false"

除了复选框之外

android:focusable="false"

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM