我想在我的activity下面的action bar中使用spinner是onCreateOptionsMenu:我使用这个教程来实现这个方法。我的问题是当活动是午餐时,onNavigationItemSelected 方法会触发并且开关/案例上的代码运行以及我为位置 0 设置的活动打开。当活动是午餐时,我应该怎么做才能防止运行开关/机箱?
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
SpinnerAdapter mSpinnerAdapter;
if(Build.VERSION.SDK_INT <= 10)
{
mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.spinner_data,android.R.layout.simple_spinner_item);
}
else
{
mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.spinner_data,android.R.layout.simple_spinner_dropdown_item);
}
ActionBar.OnNavigationListener mOnNavigationListener = new ActionBar.OnNavigationListener()
{
@Override
public boolean onNavigationItemSelected(int position, long itemId)
{
switch (position)
{
case 0:
Intent searchIntent = new Intent(ActivitySearchBusiness.this, ActivityFindBusinessCity.class);
startActivity(searchIntent);
break;
case 2:
Intent dealsIntent = new Intent(ActivitySearchBusiness.this, ActivityDeals.class);
startActivity(dealsIntent);
break;
case 3:
Intent eventsIntent = new Intent(ActivitySearchBusiness.this, ActivityEvents.class);
startActivity(eventsIntent);
break;
}
return true;
}
};
actionBar.setListNavigationCallbacks(mSpinnerAdapter,
return super.onCreateOptionsMenu(menu);
}