当我在列表视图中有更多项目并且我选择了一些复选框并将其向下滚动以选择更多复选框然后上面选择的复选框被取消选择。
请帮忙。我可以在哪里保存检查的状态和位置以及何时刷新列表。下面给出的代码。
protected void onCreate(Bundle savedInstanceState) {
dladapter = new DifferenceListAdapter(this,
prodCodeArr, prodDescArr, serialBatchArr, expDtArr, qtyArr, serialNo, 0);
diffeneceLv.setAdapter(dladapter);}
static class ViewHolder {
TextView srNotv, prodCodetv, prodDesctv, serialBatchNotv, expDatetv, qtytv;
CheckBox consCheckBox;
}
public class DifferenceListAdapter extends BaseAdapter{
Context c;
String[] prodCode, prodDesc, expDate, qty, serialNo, serialBatchNo;
//TextView srNotv, prodCodetv, prodDesctv, serialBatchNotv, expDatetv, qtytv;
EditText consumedEt, disputeEt, OTCEt, patientnameEt;
//final ArrayList<String> chkList = new ArrayList<String>();
ArrayList<Boolean> chkState;
//CheckBox consCheckBox;
private boolean checked = false;
ViewHolder viewHolder;
View row;
int f=0;
public DifferenceListAdapter(Context c, String[] prodCode, String[] prodDesc, String[] serialBatchNo, String[] expDate, String[] qty, String[] serialNo, int f){
this.c = c;
this.prodCode= prodCode;
this.prodDesc= prodDesc;
this.serialBatchNo= serialBatchNo;
this.expDate = expDate;
this.qty=qty;
this.serialNo= serialNo;
this.f= f;
chkState = new ArrayList<Boolean>();
}
public String[] getChecked(){
return chkList.toArray(new String[chkList.size()]);
}
public int getCount() {
// TODO Auto-generated method stub
return prodCode.length;
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return serialBatchNo[arg0];
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public CheckBox getCheckBox() {
return viewHolder.consCheckBox;
}
public void toggleChecked() {
checked = !checked;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final int p= position;
//if (convertView == null) {
viewHolder=new ViewHolder();
LayoutInflater inflater= (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row= inflater.inflate(R.layout.consumedstockitemrow, null);
viewHolder.consCheckBox = (CheckBox) row.findViewById(R.id.conschkbx);
viewHolder.srNotv=(TextView) row.findViewById(R.id.rowcdiffSrNoTv);
viewHolder.prodCodetv=(TextView) row.findViewById(R.id.rowcdiffProductCodeTv);
viewHolder.prodDesctv=(TextView) row.findViewById(R.id.rowcdiffProdDescTv);
viewHolder.serialBatchNotv=(TextView) row.findViewById(R.id.rowcdiffSerialBatchTv);
viewHolder.expDatetv=(TextView) row.findViewById(R.id.rowcdiffExpDtTv);
viewHolder.qtytv=(TextView) row.findViewById(R.id.rowcdiffQtyTv);
viewHolder.consCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
CheckBox cb = (CheckBox) buttonView;
if(cb.isChecked()== true)
{
if(chkList.contains(serialBatchNo[p]))
{
}
else
{
chkList.add(serialBatchNo[p]);
}
}
else
{
if(chkList.contains(serialBatchNo[p]))
{
chkList.remove(serialBatchNo[p]);
}
}
}
});
viewHolder.srNotv.setText(String.valueOf(p+1));
viewHolder.prodCodetv.setText(prodCode[p].toString());
viewHolder.prodDesctv.setText(prodDesc[p].toString());
viewHolder.serialBatchNotv.setText(serialBatchNo[p].toString());
viewHolder.expDatetv.setText(expDate[p].toString());
viewHolder.qtytv.setText(qty[p].toString());
return row;
}
}