My listview data have imageview , textview and checkbox. When I click listview data , everything is work .But checkbox value is not change . I want to implement as native android multi selected item. I want to apply onClick event not only checkbox but also imageview and textview. i.e it is effected that user click everywhere on one row
This is my code.
public class ProductListChkAdapter extends BaseAdapter {
private Context mContext;
private static CashSaleProductInfo _CashSaleProductInfo = null;
private List<CashSaleProductInfo> _listChkCashSaleProductInfo;
private int chkPrdcodeID;
private LayoutInflater inflater;
public static List<CashSaleListInfo> _listCashSaleListInfo;
private CashSaleProductLogic _sellProductLogic;
boolean[] checkBoxState;
private LayoutInflater layoutInflater;
public ProductListChkAdapter(Context paramContext,
List<CashSaleProductInfo> paramList1, int textViewResourceId) {
this.mContext = paramContext;
this._listChkCashSaleProductInfo = paramList1;
this.chkPrdcodeID = textViewResourceId;
checkBoxState = new boolean[_listChkCashSaleProductInfo.size()];
}
@Override
public int getCount() {
return (_listChkCashSaleProductInfo == null) ? 0
: _listChkCashSaleProductInfo.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(final int position, View convertView,
ViewGroup paramViewGroup) {
inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.productinfochklist, null);
TextView lblProductCode = (TextView) convertView
.findViewById(R.id.lblProductCode);
CheckBox chkPrdCode = (CheckBox) convertView
.findViewById(R.id.chkProductCode);
ImageView imgPrdCode = (ImageView) convertView
.findViewById(R.id.main_list_item_pcode);
RelativeLayout _relPrdlist = (RelativeLayout) convertView
.findViewById(R.id.relPrdlist);
imgPrdCode.setImageResource(R.drawable.c_f);
viewHolder = new ViewHolder();
viewHolder.lblProductCode = lblProductCode;
viewHolder.chkPrdCode = chkPrdCode;
viewHolder._relPrdlist = _relPrdlist;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.lblProductCode.setText(_listChkCashSaleProductInfo
.get(position).getDESC_ENG().toString());
viewHolder.chkPrdCode.setChecked(checkBoxState[position]);
viewHolder._relPrdlist.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MainActivity._CashSaleProductInfo = new CashSaleProductInfo();
// CheckBox cb = (CheckBox) v;
CheckBox cb = (CheckBox) v;
int p = position;
boolean b = checkBoxState[p];
// if (((CheckBox) v).isChecked()) {
if (!checkBoxState[position]) {
// if (cb.isChecked()) {
checkBoxState[position] = true;
// States _state = (States) cb.getTag();
MainActivity._CashSaleProductInfo
.setPRODUCT_CODE(_listChkCashSaleProductInfo.get(
position).getPRODUCT_CODE());
MainActivity._CashSaleProductInfo
.setDESC_ENG(_listChkCashSaleProductInfo.get(
position).getDESC_ENG());
MainActivity._listchkCashSaleProductInfo
.add(MainActivity._CashSaleProductInfo);
} else {
MainActivity._CashSaleProductInfo
.setPRODUCT_CODE(_listChkCashSaleProductInfo.get(
position).getPRODUCT_CODE());
MainActivity._CashSaleProductInfo
.setDESC_ENG(_listChkCashSaleProductInfo.get(
position).getDESC_ENG());
Iterator<CashSaleProductInfo> iterator = MainActivity._listchkCashSaleProductInfo
.iterator();
while (iterator.hasNext()) {
CashSaleProductInfo _CashSaleProductInfo = iterator
.next();
if (_CashSaleProductInfo.getPRODUCT_CODE().equals(
MainActivity._CashSaleProductInfo
.getPRODUCT_CODE())) {
iterator.remove();
} else {}
}
checkBoxState[position] = false;
Log.i("CC", " After "
+ MainActivity._listchkCashSaleProductInfo.size());
}
}
});
return convertView;
}
public static class ViewHolder {
TextView lblProductCode;
CheckBox chkPrdCode;
ImageView imgPrdCode;
RelativeLayout _relPrdlist;
}
}