I want to use the spinner in the action bar in my activity below, this is onCreateOptionsMenu: I use this tutorial to achieve this approach. My problem is that in the event of a lunch break, the onNavigationItemSelected method is activated and the code is run at the start of the switch / case and the activity that I set for position 0. What should I do to prevent the switch / case from starting when the activity dines?
@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); }
android actionbarsherlock android-spinner
Misagh aghakhani
source share