如何从可扩展列表中获取子位置查看android。
我想自动从可扩展列表视图setSelect中获取子位置。
答案 0 :(得分:4)
expListView.setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
final String selected = (String) expListAdapter.getChild(
groupPosition, childPosition);
Toast.makeText(getBaseContext(), selected, Toast.LENGTH_LONG)
.show();
return true;
}
});
答案 1 :(得分:0)
您必须使用Adapter的getChild(groupPosition, childPosition)
方法来检索子实例。
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(this, (String)((Map<String, String>)
adapter.getChild(groupPosition, childPosition)).get(childPosition),
Toast.LENGTH_LONG).show();
return super.onChildClick(parent, v, groupPosition, childPosition, id);
}