无法检查/取消CheckedTextView内getView [英] Unable to check/uncheck CheckedTextView inside getView

查看:219
本文介绍了无法检查/取消CheckedTextView内getView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载在一个自定义的ListView手机通讯录。每一行是含有CheckedTextView和另一个TextView的一个辨认的LinearLayout

I'm loading phone contacts in a custom ListView. Each row is a checkable LinearLayout containing a CheckedTextView and another TextView.

我喂列表视图中使用自定义ArrayAdapter。我的问题是,我无法里面getView控制CheckedTextViews()。例如,当我尝试以下

I'm feeding the list view with a custom ArrayAdapter. My problem is that I can't control CheckedTextViews inside getView(). For example when I try the following

public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        if(row == null){            
            row = inflater.inflate(layout, parent, false);
        }

        CheckedTextView checkedTextView =  (CheckedTextView) row.findViewById(R.id.checkedTextView);
        checkedTextView.setText("A");
        checkedTextView.setChecked(true);
        return row;
    }

这是应该检查每当我滚动列表视图中的每个文本视图,但是这没有发生。谁能告诉我该怎么办呢?

That's supposed to check every text view whenever I scroll the list view, but that's not happening. Can anybody tell me how to do it?

编辑:重要的是里面getView()检查,我不能只是检查所有setListAdapter后()

It's important to check it inside getView(), I can't just check all after setListAdapter()

EDIT2:这是表示各行的视图xml文件

This is the xml file showing the view of each row

<?xml version="1.0" encoding="utf-8"?>
<com.example.multiplecontacts.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <CheckedTextView
        android:id="@+id/checkedTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:checkMark="?android:attr/listChoiceIndicatorMultiple"
        android:paddingBottom="0dp"
        android:text="CheckedTextView"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/subTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Small Text"
        android:paddingTop="0dp"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</com.example.multiplecontacts.CheckableLinearLayout>

CheckableLinearLayout是一个扩展的LinearLayout和实现可检查的,因为我之前说的自定义布局。而且我已经采取了从这里

推荐答案

你在布局XML设置勾选属性的CheckedTextView?

Did you set a checkMark property for your CheckedTextView in your layout xml?

例如:安卓:勾选=机器人:ATTR / listChoiceIndicatorMultiple

CheckedTextView不只是一个文本框。您还必须注意,CheckedTextView不可作为焦点,或点击没有一些操作(因为它是专为ListView的,因此它的状态,必须由ListView的控制 setOnItemClickListener

CheckedTextView is not just a checkbox with a text. You must also note, that CheckedTextView is not focusable, or clickable without some manipulation (since it was designed for ListView and therefore it's state must be controlled by ListView's setOnItemClickListener)

setChoiceMode 应该为一个ListView进行设置。 而检查内部适配器的getView该行应通过以下方式进行: listView.setItemChecked(位置,值)

setChoiceMode should be set for a ListView. And checking of the row inside adapter's getView should be done via: listView.setItemChecked(position, value)

这篇关于无法检查/取消CheckedTextView内getView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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