每七箱检查了在ListView中的复选框 [英] Every seventh box checked with CheckBoxes in ListView

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

问题描述

我有一个ListView,有649项。列表中的每个视图具有两个LinearLayouts,一个ImageView的,几TextViews,和一个复选框。我现在有code要经过所有的复选框,并尽数,更code弄清楚哪些检查这样我就可以使用它们。但是,每当我选中一个复选框中,每七复选框上面和下面神奇地变成检查为好。计数检查框的方法返回其实我查了一些,但该方法得到的所有检查框的指数只是返回第一个X检查,不管我是否检查他们或那些7远离他们。例如,如果我签号码21,该方法返回指数3.我已经包括了一些相关的code段: 布局code在列表中的每个景观:

I have a ListView that has 649 entries. Each View in the list has two LinearLayouts, an ImageView, a few TextViews, and a CheckBox. I currently have code to go through all the CheckBoxes and count them, and more code to figure out which ones are checked so I can use them. However, whenever I check one of the CheckBoxes, every seventh CheckBox above and below it magically become checked as well. The method to count the checked boxes returns the number I actually checked, but the method to get the indices of all the checked boxes just returns the first x checked, regardless of whether I checked them or the ones 7 away from them. For example, if I check number 21, the method returns index 3. I have included some of the relevant code segments: The layout code for each View in the list:

<?xml version="1.0" encoding="utf-8"?>

    

<TextView
    android:id="@+id/id"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:textSize="20sp"/>

<LinearLayout
    android:layout_width="180dp"
    android:layout_height="50dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/name"/>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textColor="#777777"
        android:id="@+id/type"/>

</LinearLayout>
<CheckBox
    android:layout_gravity="right|center_horizontal"
    android:id="@+id/check"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:focusableInTouchMode="false"/>

检查计数方式:

    public int[] whichAreChecked()  //TODO: this should work.
{
    int listItemCount = ChooserList.getChildCount();
    ArrayList<Integer> ints=new ArrayList<Integer>();
    for(int i=0; i<listItemCount; i++)
    {
        CheckBox cbox = (CheckBox) ((View)ChooserList.getChildAt(i)).findViewById(R.id.check);
        if(cbox.isChecked())
            ints.add(i);
    }
    Log.e("durr", ""+ints.size());
    int[] result=new int[ints.size()];
    for(int i=0; i<result.length; i++)
        result[i]=ints.get(i);
    return result;
}

检查计数方式:

    public int countChecks()
{
    int checked=0;
    int listItemCount = ChooserList.getChildCount();
    for(int i=0; i<listItemCount; i++)
    {
        CheckBox cbox = (CheckBox) ((View)ChooserList.getChildAt(i)).findViewById(R.id.check);
        if(cbox.isChecked())
            checked++;
    }
    Log.e("countChecks()", ""+checked);
    return checked;
}

如果我可以添加任何额外的信息,请咨询!

If I can add any extra info, please ask!

推荐答案

哦,我倒想你是误会什么了 getChildCount() getChildAt() 的方法做。这些实际上只得到的渲染的意见。除非我误解的东西在这里,如果你有650ish行,你不能完成你想要与正在呈现的观点。相反,你应该实施 onItemClickListener (或者,这东西触发时复选框被点击)和复选框被选中之后,保存状态到模型。

Hmmmm I think you misunderstood what the getChildCount() and getChildAt() methods do. Those will actually get only the rendered views. Unless I misread something here, if you have 650ish rows you cannot accomplish what you want with the views that are being rendered. Instead, you should implement an onItemClickListener (or, alternatively, something that fires when the checkboxes are clicked) and after the checkbox is checked, save that state into your model.

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

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