有以下代码:
@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;
}
此代码有效并向我显示我的ExpandableListView,但存在以下问题 - 子项目无法点击!正如你所看到的,我已经为孩子点击设置了听众,但我从未见过任何祝酒词!我该如何解决?
更新:我使用自定义视图作为子项,但是如果我为任何android.R.layout布局更改它,它将起作用!
答案 0 :(得分:1)
为子项目的自定义视图中的每个视图设置android:focusable="false"
。
答案 1 :(得分:-1)
在Adapter类中,从重写方法ischild select中返回true。 这样做对我有用。