Как мне установить OnCheckedChangeListener для каждого флажка childelements?
Я не могу понять это. Когда я отмечаю флажок, я хочу, чтобы всплыл тост, сообщающий мне, какого ребенка я проверял
Источник:
public class ExpandableActivity extends ExpandableListActivity {
private String[] alphabet = { "a", "b", "c", "d", "e", "f", "g" };
private String c;
ArrayList<ArrayList<Integer>> check_states = new ArrayList<ArrayList<Integer>>();
private Context context;
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Create an array of Strings, that will be put to our ListActivity
setContentView(R.layout.expandablelist);
Bundle extras = getIntent().getExtras();
c = extras.getString("category");
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
this, createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item.
new int[] { R.id.row_name }, // ID of each group item.-Data
// under the key goes into
// this TextView.
createChildList(), // childData describes second-level
// entries.
R.layout.child_row, // Layout for sub-level entries(second
// level).
new String[] { "Sub Item" }, // Keys in childData maps to
// display.
new int[] { R.id.grp_child } // Data under the keys above go
// into these TextViews.
);
setListAdapter(expListAdapter); // setting the adapter in the list.
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private List createGroupList() {
ArrayList result = new ArrayList();
for (String s : alphabet) { // 15 groups........
HashMap m = new HashMap();
if (getResources().getIdentifier(c + s + "_name", "string",
"dk.android.houseenabler") != 0) {
int id = getResources().getIdentifier(c + s + "_name",
"string", "dk.android.houseenabler");
getResources().getText(id);
m.put("Group Item", getResources().getText(id)); // the key and
// it's
// value.
} else {
return result;
}
result.add(m);
}
return result;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private List createChildList() {
ArrayList<ArrayList> result = new ArrayList<ArrayList>();
for (String s : alphabet) {
if (getResources().getIdentifier(c + s + "_name", "string",
"dk.android.houseenabler") != 0) {
int id = getResources().getIdentifier(c + s, "array",
"dk.android.houseenabler");
String[] Rchilds = getResources().getStringArray(id);
ArrayList<HashMap> secList = new ArrayList<HashMap>();
for (String d : Rchilds) {
HashMap childs = new HashMap();
childs.put("Sub Item", d);
secList.add(childs);
}
result.add(secList);
} else {
return result;
}
}
return result;
}
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// GET TITLE
int idTitle = getResources().getIdentifier(c + alphabet[groupPosition],
"array", "dk.android.houseenabler");
String[] Rchilds = getResources().getStringArray(idTitle);
// GET Desctiption
int idDesc = getResources().getIdentifier(
c + alphabet[groupPosition] + "_desc", "array",
"dk.android.houseenabler");
String[] RDesc = getResources().getStringArray(idDesc);
Intent intent2 = new Intent().setClass(this, Description.class);
intent2.putExtra("title", Rchilds[childPosition]);
intent2.putExtra("description", RDesc[childPosition]);
startActivity(intent2);
return true;
}
/* This function is called on expansion of the group */
public void onGroupExpand(int groupPosition, View v, ViewGroup vg) {
}
}
Вот изображение запущенного приложения.