我有一個ExpandableListView,我想在單擊組時記錄組位置。不幸的是,下面的代碼總是返回0,就好像我在第0組中點擊一樣。Android ExpandableListView組位置始終爲0
exList.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
groupPosition = ExpandableListView.getPackedPositionGroup(id);
Log.i("group position", groupPosition + "");
return false;
}
});
我也對團體和孩子的其中工程權longclicklistener:
exList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
groupPosition = ExpandableListView.getPackedPositionGroup(id);
...
}
任何想法?
您是否使用ExpandableListView的自定義適配器? – Cata 2012-04-09 06:49:44
是的。我的其他聽衆工作正確 – erdomester 2012-04-09 07:04:15
好的,請確保您的getItem和getItemId方法返回有效的值,而不是0 ..(在您的自定義適配器),你也可以看看這個適配器http://developer.android.com/resources/ samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html – Cata 2012-04-09 07:15:13