您好,我在下面创建了左侧导航抽屉。当我们单击父节点时,它将转到父页面。
在父菜单下有一些子菜单,这些子菜单被称为chid节点。
现在我的问题是,如果我单击父级或子级总是转到一个子节点。
有谁能帮助我在哪里做错了
mDrawerList.setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Log.d("CHECK", "child click");
int index = parent.getFlatListPosition(ExpandableListView.getPackedPositionForChild(groupPosition, childPosition));
parent.setItemChecked(index, true);
selectItem(childPosition);
return true;
}
});
private void selectItem(int position) {
selectedPosition = position;
mDrawerLayout.closeDrawer(navDrawerView);
// update the main content by replacing fragments
Fragment fragment = new PlanetFragment();
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, selectedPosition);
fragment.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(selectedPosition, true);
setTitle(mPlanetTitles[selectedPosition]);
}