gpt4 book ai didi

java - ListView 与 CheckBox 滚动问题

转载 作者:太空宇宙 更新时间:2023-11-04 11:46:56 25 4
gpt4 key购买 nike

我有 Android 程序,但我的 ListView 无法正常工作。如果 ListView 有更多滚动项目,当我要单击最后一个复选框并滚动其检查另一个项目时。请找到我的代码示例。请帮我解决这个问题。

这是我的适配器类 getView 代码

    @SuppressLint("InflateParams")
public View getView(int position, View convertView, ViewGroup parent) {

View vi = convertView;
if(convertView==null){
vi = inflater.inflate(R.layout.unsettled_invoice_layout, null);
holder = new ViewHolder();
holder.desc = (TextView) vi.findViewById(R.id.usinvoicedesc);
holder.chkbox = (CheckBox) vi.findViewById(R.id.selected);
holder.chkbox.setOnClickListener(new OnItemClickListener(position));
vi.setTag(holder);
vi.setTag(R.id.selected, holder.chkbox);
} else
holder=(ViewHolder)vi.getTag();
if(data.size()<=0){
holder.desc.setText("No Data");
}else{
tempValues=null;
tempValues = (Invoice)data.get(position);
if(mode == 1){
int myColor = Color.rgb(0, 128, 0);
if(tempValues.getStatus() == 2){
myColor = Color.rgb(0, 128, 0); // Green
holder.chkbox.setChecked(false);
}else if(tempValues.getStatus() == 3){
myColor = Color.rgb(128, 0, 0); // Red
holder.chkbox.setChecked(true);
}
holder.desc.setBackgroundColor(myColor);
}
holder.desc.setText(tempValues.toString());
vi.setOnClickListener(new OnItemClickListener( position));
}
return vi;
}

这是我用于 android 的layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:clickable="false"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:paddingTop="0dip"
android:textColor="#000000" >

<LinearLayout
android:id="@+id/usinvoicelayout"
android:layout_width="fill_parent"
android:layout_height="95dp"
android:layout_marginBottom="3dp"
android:layout_marginTop="2dip"
android:clickable="false"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="horizontal"
android:paddingTop="0dip" >

<TextView
android:id="@+id/usinvoicedesc"
android:layout_width="520dp"
android:layout_height="90dp"
android:layout_gravity="start"
android:gravity="center_vertical"
android:textColor="#FFFF00"
android:textSize="18sp" />

<CheckBox
android:id="@+id/selected"
android:layout_width="50dp"
android:layout_height="80dp"
android:layout_marginStart="15dip"
android:button="@drawable/checkbox_background"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>

</LinearLayout>

最佳答案

为此,您需要维护一个 HashMap 。当您单击复选框时,在设置复选框检查 HashMap 中的检查位置之前,将位置放入散列映射和 getview 中。如果存在则选中复选框。

关于java - ListView 与 CheckBox 滚动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42265048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com