when i have more items in listview and i select some checkbox and scroll it down to select more checkbox then checkbox which were selected above gets deselect.
Plz help. where i can save checked state and position and when i do refresh list.
code given below.
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;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…