我通过扩展 BaseExpandableListAdapter 来填充扩展列表视图。
ChildView 的代码:
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
LayoutInflater in=getLayoutInflater();
convertView=in.inflate(R.layout.details, null);
//set text for various TextViews from ArrayList1
return convertView;
}
GroupView 的代码:
public View getGroupView(final int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
LayoutInflater li= getLayoutInflater();
convertView=li.inflate(R.layout.list, null);
//add data to ArrayList1 and set text for various TextViews
return convertView;
}
如果一个组被展开并且我长按任何后续组,onItemLongClick 方法将获取参数 itemIndex 的(实际索引 + 1)值。因此,我得到 arrayindexoutofbounds 异常。
elview.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int itemIndex, long arg3) {
Log.e("index selected", itemIndex+"");
return false;
}});
我在这里错过了什么吗?