有下面的代碼:ExpandableListView項目無法點擊
@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,但存在以下問題 - 子項不能點擊!正如你所看到的,我已經爲孩子點擊設置了監聽者,但我從未見過任何Toasts!我該如何解決它?
更新:我使用我的自定義視圖的子項,但如果我改變它的任何android.R.layout佈局它將工作!
「如果我改變它的任何android.R.layout佈局它將工作!」發佈您的自定義佈局,它可能會在觸及事件到達OnChildClickListener之前消耗它。 – Sam