我正在尝试修改 SherlockNavigationDrawer 中的示例。它只有一个片段,但我不知道要添加更多片段,每个片段都有自己的布局,对所有人都不一样......
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout frame = new FrameLayout(this);
frame.setId(CONTENT_VIEW_ID);
setContentView(frame, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
if (savedInstanceState == null) {
setInitialFragment();
}
}
private void setInitialFragment() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(CONTENT_VIEW_ID, MainFragment.newInstance()).commit();
}
但我的想法是在单击 MainFragment 内的列表视图中的项目时调用一个新片段
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mContent.setText(Shakespeare.DIALOGUE[position]);
mActionBar.setTitle(Shakespeare.TITLES[position]);
mDrawerLayout.closeDrawer(listView);
//START A NEW FRAGMENT HERE DEPENDING OF THE POSITION CLICKED
}
}
有什么想法吗?提前致谢