我關注此:Programmatically collapse a group in ExpandableListView。我希望用戶一次只能擴展一個組,並平滑地滾動到正確的位置。我已經寫了實現OnGroupClickListener自定義適配器:ExpandableListview OnGroupClickListener不生效
public class CategoriesListAdapter extends BaseExpandableListAdapter implements OnGroupClickListener {
private ExpandableListView expListView;
private int lastExpandedGroupPosition = -1;
// I get the expListView in the constructor...
@Override
public boolean onGroupClick(ExpandableListView parent, View view, int groupPosition, long id) {
parent.smoothScrollToPosition(groupPosition);
if (parent.isGroupExpanded(groupPosition)) {
parent.collapseGroup(groupPosition);
} else {
parent.expandGroup(groupPosition);
}
return true;
}
@Override
public void onGroupExpanded(int groupPosition) {
if (groupPosition != lastExpandedGroupPosition) {
expListView.collapseGroup(lastExpandedGroupPosition);
}
super.onGroupExpanded(groupPosition);
lastExpandedGroupPosition = groupPosition;
}
}
不幸的是,onGroupClick事件從來沒有發射。(我已經把一些日誌的方法內)。我也試過:
expListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View view, int groupPosition, long id) {
// Same as above...
});
}
相同結果爲這種替代...任何想法?
您可以參考[這裏](http://developer.android.com/reference/android /widget/ExpandableListView.OnGroupClickListener.html) –
導入是正確的。如果我將返回值設置爲false,則在第一次點擊時我的組未被正確摺疊(我需要2次點擊),並且沒有任何事件正在被解僱。無論如何,爲什麼onGroupClickListener覆蓋適配器不起作用?最後一個:爲什麼滾動在4.3上平滑,在2.3.3上滾動太快? – Jumpa