使用复选框以虚假的可获得焦点,依然prevents列表视图点击 [英] Using a checkbox with a false focusable, still prevents listview clicks

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

问题描述

您好我已经阅读了不少关于Android中的复选框/ 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();

    }

如果我再改复选框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""

添加了两条线,使onListItemClick火正确。

Adding the both lines makes the onListItemClick fire correctly.

这篇关于使用复选框以虚假的可获得焦点,依然prevents列表视图点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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