我想知道,如何获取在ExpandableListView
我有一个BaseExpandableListAdapter
,这是我的方法:
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final Foo children = (Foo) getChild(groupPosition, childPosition);
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item, null);
}
// view stuff
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// how to get the clicked child object of type Foo?
}
});
convertView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// also how to get it here?
return true;
}
});
return convertView;
}
如何为点击和长按一下监听器获取Foo
类型的Child元素?
答案 0 :(得分:0)
在代码中使用onChildClick
方法。单击子项时会自动调用此方法。使用this链接进行长按。
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
return true;
}