我有Android程序,但我的列表視圖無法正常工作。 如果列表視圖有更多的項目與滾動,當我要點擊最後一個複選框與滾動檢查另一個項目。請找到我的代碼sample.please幫我解決這個問題。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;
}
這是layout.xml我用它爲Android
<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>
我認爲你的問題有很多問題和解決方案。嘗試搜索 –