一个ListView中的复选框 [英] Checkbox within a ListView

查看:168
本文介绍了一个ListView中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想填充一个列表视图,其中包含复选框作为一个Android应用程序列表中的项目。我实现了一个列表视图,但如果我检查的复选框中的任何一个在列表中它会检查在ListView一些其他列表..在此先感谢。

I wish to populate a listview which contains checkbox as list items in an android application. I have implemented a listview, but if I check anyone of the checkboxes in the list it checks some other lists in the listview.. Thanks in advance..

有关自定义布局:

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

    <CheckBox
        android:id="@+id/chk_check"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:layout_marginLeft="10dp"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="@string/check_text"/>
</LinearLayout>

对于ListView:

For the listview:

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:orientation="vertical" >

            <ListView
                android:id="@+id/lv_list_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </ListView>
</LinearLayout>

有关适配器:

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    final ListHolder holder;
    row = convertView;
    if (row == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);
        holder = new ListHolder();
        holder.chk = (CheckBox) row
            .findViewById(R.id.chk_check);
        row.setTag(holder);
    } else {
        holder = (ListHolder) row.getTag();
    }

    if (list != null) {
        String data = list.get(position);
        holder.chk.setText(data);

    }

    return row;
}

public class ListHolder {

    CheckBox chk;
}

所有工作正常,但复选框选中自己,当我滚动列表视图。

All are working fine, but the checkboxes checked itself when I scroll the listview.

推荐答案

请看看这些链接。我想,你会发现你在找什么位置: -

Please look at these links. I think you will find what you are looking for here :-

HTTP://sunil-android.blogspot。在/ 2013/04 / Android的列表视图,复选框,example.html http://amitandroid.blogspot.in/2013/03 /android-listview-with-checkbox-and.html http://www.vogella.com/articles/AndroidListView/article.html

这篇关于一个ListView中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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