我使用android studio创建了默认导航抽屉应用程序。使用导航抽屉更改另一个内容
然后我wan't创建具有不同component.How我可以改变相关的菜单中点击该内容不同的布局。
我想单击导航菜单链接时更改这两个内容。
虚设内容(阳痿:内容主体是传出,不能使用可重复使用的片段)
我使用android studio创建了默认导航抽屉应用程序。使用导航抽屉更改另一个内容
然后我wan't创建具有不同component.How我可以改变相关的菜单中点击该内容不同的布局。
我想单击导航菜单链接时更改这两个内容。
虚设内容(阳痿:内容主体是传出,不能使用可重复使用的片段)
如果我明白你的问题的权利,你可以有一个的FrameLayout作为一个容器。在列表项目上单击添加或替换适当的片段到容器。
如果你需要开始一个新的活动,你也可以这样做。
可以效仿的榜样@
http://developer.android.com/training/implementing-navigation/nav-drawer.html
我想创建一个不同的布局与不同component.How我可以 改变相关的菜单中,点击该内容。
=>我完全明白你的意思,你想改变内容aka布局(活动),每当用户从导航抽屉选择任何项目。
如果是这种情况,那么您必须用您希望显示的新片段替换当前片段。
例如:
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
selectItem(position);
}
}
/** Swaps fragments in the main content view */
private void selectItem(int position) {
// Create a new fragment and specify the planet to show based on position
Fragment fragment = new PlanetFragment();
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
fragment.setArguments(args);
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
// Highlight the selected item, update the title, and close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
有关详细的例如:http://developer.android.com/training/implementing-navigation/nav-drawer.html