Mam taki problem, że posiadam rozwijaną listę z dwoma grupami. Do każdego pola child jest przypisany checkbox i ikona usuwania.
O ile udało mi się przypisać funkcjonalność do ikony usuwania to z checkbox'em nie mogę sobie poradzić.
Próbowałem bazować na tym przykładzie, ale niestety się nie udało :/ http://stackoverflow.com/questions/5068668/android-expandablelistview-with-checkbox-controlling-checked-state
Gdyby ktoś miał chwile przeanalizować kod i udzielić mi wskazówek, porad jak sobie z tym poradzić, od czego zacząć, będę bardzo wdzięczny ;)
Poniżej kod adaptera.
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Activity context;
private Map<String, List<String>> noteCollections;
private List<String> notes;
public ExpandableListAdapter(Activity context, List<String> notes,
Map<String, List<String>> noteCollections) {
this.context = context;
this.noteCollections = noteCollections;
this.notes = notes;
}
public Object getChild(int groupPosition, int childPosition) {
return noteCollections.get(notes.get(groupPosition)).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String note = (String) getChild(groupPosition, childPosition);
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.child_item, null);
}
TextView item = (TextView) convertView.findViewById(R.id.note);
ImageView delete = (ImageView) convertView.findViewById(R.id.delete);
delete.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Do you want to remove?");
builder.setCancelable(false);
builder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
List<String> child =
noteCollections.get(notes.get(groupPosition));
child.remove(childPosition);
notifyDataSetChanged();
}
});
builder.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
item.setText(note);
return convertView;
}
public int getChildrenCount(int groupPosition) {
return noteCollections.get(notes.get(groupPosition)).size();
}
public Object getGroup(int groupPosition) {
return notes.get(groupPosition);
}
public int getGroupCount() {
return notes.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String noteName = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_item,
null);
}
TextView item = (TextView) convertView.findViewById(R.id.notes);
item.setTypeface(null, Typeface.BOLD);
item.setText(noteName);
return convertView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}