单击DrawerLayout navigationView项时,我应该使用什么函数来打开活动,我是否需要为该活动制作对象?
到目前为止,这是我的代码:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_profile) {
// Handle the camera action
} else if (id == R.id.nav_cv) {
} else if (id == R.id.nav_subscription) {
} else if (id == R.id.nav_logout) {
}
答案 0 :(得分:0)
你可以打开这样的活动。
意图I =新意图(MainActivity.this,actvitytoopen.class); StartActivity(I);
答案 1 :(得分:0)
您最好使用片段而不是活动,并使用FragmentManager更改它们。您只需在Google / Youtube上搜索即可找到大量教程。
答案 2 :(得分:0)
您可以通过
开始新的活动Intent intent = new Intent(this,NextActivity.class);
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
有关详细信息,请参阅https://developer.android.com/training/basics/firstapp/starting-activity.html
答案 3 :(得分:0)
I spent a lot of time trying to call a new activity by clicking on navigation drawer item . but it is virtually impossible and if it is possible in any other way I tried, then it is sure that on the called activity there will be no drawer navigation drawer then. Fragment is a part of similar activity so calling fragment is the correct way. If you are calling fragment, navigation drawer will still be there on the side pane and you would be able to select between different items of the drawer.