我是android的新手。我在我的应用程序中创建了滑动菜单,并且当我点击抽屉中的列表项时能够访问片段。如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
displayView(0);
}
@Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}
private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
fragment = new HomeFragment();
title = getString(R.string.title_home);
break;
case 1:
fragment = new DailyPromotion();
title = getString(R.string.title_friends);
break;
case 2:
fragment = new WeeklyPromotion();
title = getString(R.string.title_messages);
break;
case 3:
fragment = new OurProducts();
title = getString(R.string.title_products);
break;
case 4:
fragment= new AboutUsFragment();
title= getString(R.string.title_aboutus);
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.commit();
// set the toolbar title
getSupportActionBar().setTitle(title);
}
}
它就像一个魅力。但是当我点击任何项目时我想打开一个活动,让我们说“case 0:”打开一个活动而不是片段。提前致谢
答案 0 :(得分:1)
sh: 0: getcwd() failed: No such file or directory