簡體   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