我有4个组的ExpandableListView。如果位置0处的组被展开,那么当我单击位置1处的组时,该组的选择(红色)不会显示。如果我在第3位扩展组,然后在第2位扩展,一切都没问题,选择就会显示出来。我有4个听众,听取组选,扩展,折叠和子按下。在选定,展开和折叠的侦听器上调用displayView()方法。然后根据位置方法应该选择组并显示新的片段或者不显示。我知道方法得到正确的位置,应该选择。怎么了?
我的列表听众:
mDrawerList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
displayView(groupPosition);
return false;
}
});
mDrawerList.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
displayView(groupPosition);
}
});
mDrawerList.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
displayView(groupPosition);
}
});
mDrawerList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
return false;
}
});
我的displayView方法:
private void displayView(int position) {
// update the main content by replacing fragments
android.support.v4.app.Fragment fragment = null;
switch (position) {
case 1:
fragment = new Eat();
break;
case 3:
fragment = new About();
break;
default:
break;
}
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
//here method have a right position of a group
if (fragment != null) {
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
// update selected item and title, then close the drawer
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
}