I have an arrayList in Custom Adapter, consisting of some strings and checkbox. and i want to set checkbox checked automatically with certain condition, but how to set the code so the checkbox checked automatically.
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data = d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if(convertView == null)
vi = inflater.inflate(R.layout.list_row, null);
TextView no = (TextView)vi.findViewById(R.id.txt_no);
TextView code = (TextView)vi.findViewById(R.id.txt_code);
TextView name = (TextView)vi.findViewById(R.id.txt_asset);
TextView dept = (TextView)vi.findViewById(R.id.txt_dept);
CheckBox status = (CheckBox)vi.findViewById(R.id.cb_stat);
HashMap<String, String> asset = new HashMap<String, String>();
asset = data.get(position);
//Setting all values in listview
no.setText(asset.get(ListLocationActivity.KEY_NO));
code.setText(asset.get(ListLocationActivity.KEY_CODE));
name.setText(asset.get(ListLocationActivity.KEY_NAME));
dept.setText(asset.get(ListLocationActivity.KEY_DEPT));
return vi;
}
This is my condition when i get the result, i want set checked the checkbox which the result suitable with the code in arraylist
for (int i = 0; i < assetList.size(); i++) {
if (assetList.get(i).get(KEY_CODE).equals(scanAsset)){
//set checked in certain list asset
//(Here i confused how i can set the checkbox in list suitable with the code asset)
Log.i("Asset code is ", scanAsset);
}
}
this code is work fine without set value in checkbox, Anyone can help me to solve this case, please . . . . Thank you before
status.setChecked(true)?getViewthen just call notifyDataSetChanged on the adapter to rebuild after you've changed the condition that causessetCheckedto be true ingetView