[英]ExpandableListView items are not clickable
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! 这段代码可以正常工作,并向我展示了我的ExpandableListView,但是存在以下问题-子项不可点击! As you can see, I've set listener for click by child, but I've never seen any Toasts!
如您所见,我已经设置了侦听器以供孩子点击,但是我从未见过任何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! 更新:我将自定义视图用于子项,但如果将其更改为任何android.R.layout布局,它将起作用!
为子项的自定义视图中的每个视图设置android:focusable="false"
。
In Adapter class return true from overridden method ischild selectable. 在适配器类中,从覆盖的方法ischild selectable返回true。 Do this it worked for me.
这样做对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.