我的操作栏栏上有一个下拉菜单,在菜单中选择任何内容后,该应用程序将打开列表中所选内容下方的所有活动。例如,如果在菜单中我有群组,聊天,朋友,选择设置,如果我选择聊天,它将打开聊天活动以及朋友和设置。
我如何才能使应用程序只打开那些被选中的活动
MainActivity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
// Configure the search info and add any event listeners
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat
.getActionView(searchItem);
return true;
}
// Actionbar items
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
// searchView.OnQueryTextListener();
case R.id.action_chat: {
// Starting the tabbed browsing for friends, indie/group chats
Intent i = new Intent(MainActivity.this,
GroupIndFriendActivity.class);
startActivity(i);
}
case R.id.action_alarms: {
Intent alerts = new Intent(MainActivity.this,
MyAlerts.class);
startActivity(alerts);
}
case R.id.action_favorite:
// openSettings();
case R.id.action_favorite_specials:
// openSettings();
case R.id.action_settings: {
Intent settings = new Intent(MainActivity.this,
ApplicationSettings.class);
startActivity(settings);
}
default:
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
您的break
块中需要case
个语句,否则每个后续case
都会执行。{/ p>