在自定义视图使用CheckedText的ListView与CHOICE_MODE_MULTIPLE [英] ListView with CHOICE_MODE_MULTIPLE using CheckedText in a custom view

查看:224
本文介绍了在自定义视图使用CheckedText的ListView与CHOICE_MODE_MULTIPLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多如何使用的问题 CheckedTextView 但我不能让它正常工作。

There are plenty of questions of how to use CheckedTextView but I can't make it work correctly.

我有一个的CursorAdapter 与有一个 CheckedTextView Android的自定义视图: ID =@机器人:ID / text1中的。我已经使用机器人:ID /文本1 因为有提到,如果你使用它,你会得到的选择方式多为免费不同的问题

I have a CursorAdapter with a custom view which has a CheckedTextView with android:id="@android:id/text1". I have used android:id/text1 because there are different questions that mention that if you use it you will get the choice mode multiple for free.

如果我做这样的事情:

final long[] checkedIds = mListView.getCheckedItemIds();
for ( int i = 0 ; i < mListView.getCheckedItemCount() ; i++ ) {
    Log.d(TAG, "id checked: " + checkedIds[i]);
}

我得到的所有的IDS检查没有问题,但我不能看到的ListView任何视觉反馈

在换句话说逻辑是好的,但是当我点击 CheckedTextView 绿色打勾不显示。

In other words the logic is fine but when I click the CheckedTextView The green tick doesn't show up.

我读的ListView SRC code和我找不到任何引用机器人:ID /文本1 ,使我不知道是否我应该处理控件的选中状态我自己。

I was reading the ListView src code and I couldn't find any reference to android:id/text1 and makes me wonder if I should handle widget's checked state myself.

任何人都可以当场其中机器人:ID /文本1 是用来做小部件检查或不

Can anyone spot where android:id/text1 is used to make the widget checked or not?

推荐答案

根据我的code了解,该行已实施可检查

Based on my read of the code, the row has to implement Checkable:

if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
    if (child instanceof Checkable) {
        ((Checkable) child).setChecked(mCheckStates.get(position));
    }
}

本作品为股票行的布局与选择模式的列表,因为该行是 CheckedTextView ,它实现可检查

This works for the stock row layouts for lists with choice mode because the row is a CheckedTextView, which implements Checkable.

因此​​,可检查接口添加到您的自定义查看,委托该接口的方法来对 CheckedTextView ,并看看是否能解决了。

So, add the Checkable interface to your custom View, delegating the interface's methods to the CheckedTextView, and see if that works out.

这篇关于在自定义视图使用CheckedText的ListView与CHOICE_MODE_MULTIPLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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