使用包含假焦点的复选框,仍然会阻止列表视图点击 [英] Using a checkbox with a false focusable, still prevents listview clicks

查看:121
本文介绍了使用包含假焦点的复选框,仍然会阻止列表视图点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello我已经阅读了很多关于Android的CheckBox / ListView问题。所以我已经尝试了一些问题。

Hello I've already read quite a bit about the CheckBox/ListView problems in Android. So I've tried a number of issues.

要开始我的布局为一行看起来像这样。

To start my layout for a row looks like this.

  <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

So then I tried adding this to my ListActivity

 ListView listview = getListView();
 listview.setItemsCanFocus(false);

然后尝试使用onListItemClick上的断点运行它,仍然没有命中(当然运行调试) 。

And then attempted to run it with a breakpoint on onListItemClick, still no hit (running debugging of course).

这是我的onListItemClick,以便您查看。

This is my onListItemClick in case you want to see.

@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, ,但我从来没有这样做过,我宁愿弄清楚到底是什么错在这里,当其他人解决这个问题。

If I then change the Checkbox to CheckTextView, it does work, however I've never done that before, and I'd rather figure out exactly what's wrong here when other people have solved this. Any Thoughts?

推荐答案

显然我错过了

android:clickable="false"



under the Checkbox in addition to

android:focusable="false"

$ b b

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

Adding the both lines makes the onListItemClick fire correctly.

这篇关于使用包含假焦点的复选框,仍然会阻止列表视图点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆