There is the following code:
@Override
public void showDialog(final Context context) {
AlertDialog.Builder builder=new AlertDialog.Builder(context);
LayoutInflater inflater=LayoutInflater.from(context);
View view=inflater.inflate(R.layout.dialog_year_days, null);
ExpandableListView list=(ExpandableListView)view.findViewById(R.id.dialogYearDaysList);
SimpleExpandableListAdapter adapter=new
SimpleExpandableListAdapter(context, createGroups(), android.R.layout.simple_expandable_list_item_2,
new String[]{"name"}, new int[]{android.R.id.text1}, createChildren(),
R.layout.list_item_day_of_year, new String[]{"name"}, new int[]{R.id.listItemDayOfYearName});
list.setAdapter(adapter);
list.setClickable(true);
list.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(context, "123", Toast.LENGTH_LONG).show();
return true;
}
});
builder.setView(view);
builder.setTitle("Choose days");
builder.create().show();
}
public List<Map<String, ?>> createGroups() {
List<Map<String, ?>> list = new ArrayList<Map<String, ?>>();
for (int i = 0; i < 12; i++) {
Map<String, String> item = new HashMap<String, String>();
item.put("name", DAYS[i]);
list.add(item);
}
return list;
}
public List<List<Map<String, ?>>> createChildren() {
List<List<Map<String, ?>>> list = new ArrayList<List<Map<String,?>>>();
for (int i = 0; i < 12; i++) {
List<Map<String, ?>> itemList = new ArrayList<Map<String, ?>>();
for (int j = 0; j < COUNT_OF_DAYS[i]; j++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("name", String.valueOf(j+1));
itemList.add(item);
}
list.add(itemList);
}
return list;
}
This code works and shows me my ExpandableListView, but there is the following problem – child items aren’t clickable! As you can see, I’ve set listener for click by child, but I’ve never seen any Toasts! How can I fix it?
UPDATE: I use my custom view for child item, but if I change it for any android.R.layout layout it will work!
Set
android:focusable="false"for each view in your custom view for child item.