android-在ListView中用CheckBoxes选中的每个第七个框

android-在ListView中用CheckBoxes选中的每个第七个框,第1张

概述我有一个649个条目的ListView.列表中的每个视图都有两个LinearLayout,一个ImageView,一些TextView和一个CheckBox.我目前拥有遍历所有CheckBox并对其进行计数的代码,还有更多代码可以找出已选中的复选框,以便我可以使用它们.但是,每当我选中其中一个CheckBox时,它上方和下方的每七

我有一个649个条目的ListVIEw.列表中的每个视图都有两个linearLayout,一个ImageVIEw,一些TextVIEw和一个CheckBox.我目前拥有遍历所有CheckBox并对其进行计数的代码,还有更多代码可以找出已选中的复选框,以便我可以使用它们.但是,每当我选中其中一个CheckBox时,它上方和下方的每七个CheckBox都会神奇地被选中.计数复选框的方法返回我实际检查的数字,但是获取所有复选框的索引的方法仅返回第一个被检查的x,而不管我是否选中了它们,也没有返回7.例如,如果我检查数字21,则该方法返回索引3.我已经包括一些相关的代码段:
列表中每个视图的布局代码:

<?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;}

如果我可以添加任何其他信息,请询问!

解决方法:

嗯,我认为您误解了getChildCount()和getChildAt()方法的作用.这些实际上只会得到渲染的视图.除非我在这里误读了一些内容,否则如果您有650行,您将无法使用呈现的视图来完成所需的 *** 作.相反,您应该实现一个onItemClickListener(或者,或者,当单击复选框时触发的东西),并在选中复选框之后,将该状态保存到模型中.

总结

以上是内存溢出为你收集整理的android-在ListView中用CheckBoxes选中的每个第七个框全部内容,希望文章能够帮你解决android-在ListView中用CheckBoxes选中的每个第七个框所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1093900.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存