mercredi 31 décembre 2014

CheckBox in ChildView of ExpandableListView

In my android application, I have an ExpandableListView with each group having only one child, which contains a checkbox. I'm having trouble in setting the value of the checkboxes.


I'm retrieving the values of checkbox from database and storing it in an integer ArrayList with values 0 & 1 for checked and unchecked respectively



ArrayList<Integer> trustedList = new ArrayList<Integer>();


Initially, I've put all the entries in database as 1.


The Adapter class for ExpandableListView is as follows :



class DataAdapter extends BaseExpandableListAdapter {

private Context context;
LayoutInflater lat = getLayoutInflater();

CheckBox cb;

public DataAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}

@Override
public View getChildView(int group, int child, boolean arg2, View v,
ViewGroup arg4) {
// TODO Auto-generated method stub

v = lat.inflate(R.layout.inflate_list, null);
cb = (CheckBox) v.findViewById(R.id.checkBox1);

if (trustedList.get(group) == 1)
cb.setChecked(true);
else
cb.setChecked(false);

return v;
}
}


But I'm getting unchecked values for the checkboxes. Also, on checking the checkbox and collapsing and expanding the group, I'm getting unchecked checkbox again.


Please can somebody help me out??





Aucun commentaire:

Enregistrer un commentaire