以下是我的申请代码。香港专业教育学院曾尝试过这方面的工作,但没有遇到任何对我来说成功的事情。没有改变碎片我可以做什么。
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.my_account) {
} else if (id == R.id.nav_news) {
} else if (id == R.id.nav_live) {
} else if (id == R.id.nav_media) {
} else if (id == R.id.nav_calendar) {
} else if (id == R.id.nav_results) {
} else if (id == R.id.nav_about) {
} else if (id == R.id.nav_shop) {
} else if (id == R.id.nav_social_media) {
} else if (id == nav_fanzone) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
答案 0 :(得分:0)
将 onNavigationItemSelected()更改为:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
switch(item.getItemId()){
case R.id.my_account:
//Do code here
break;
case R.id.nav_news:
//Do code here
break;
case R.id.nav_live:
//Do code here
break;
case R.id.nav_media:
//Do code here
break;
case R.id.nav_calendar:
//Do code here
break;
case R.id.nav_results:
//Do code here
break;
case R.id.nav_about:
//Do code here
break;
case R.id.nav_shop:
//Do code here
break;
case R.id.nav_social_media:
//Do code here
break;
case R.id.nav_fanzone:
//Do code here
break;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
对于更改活动,只需在所有切换案例中添加:
Intent intent=new Intent(your_activity.this,your_next_activity.class);
startActivity(intent);