public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) { this.mDecorToolbar.setDropdownParams(adapter, new NavItemSelectedListener(callback)); }
public NavItemSelectedListener(OnNavigationListener listener) { this.mListener = listener; }
@Override public void onCreate(Bundle savedState) { super.onCreate(savedState); mSavedState = savedState; setContentView(R.layout.activity_standard_fragment); actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.finances_tabs_names, R.layout.item_actionbar_spinner); ActionBar.OnNavigationListener mOnNavigationListener = new OnNavigationListener() { String[] tabNames = getResources().getStringArray( R.array.finances_tabs_names); @Override public boolean onNavigationItemSelected(int position, long rowId) { if (mSavedState != null) { int savedPosition = mSavedState.getInt( BUNDLE_POSITION_NAME, Integer.MIN_VALUE); if (savedPosition != Integer.MIN_VALUE) { mSavedState.putInt(BUNDLE_POSITION_NAME, Integer.MIN_VALUE); actionBar.setSelectedNavigationItem(savedPosition); return false; } else { if (previousPosition == position) { return false; } } } FragmentTransaction ft = getSupportFragmentManager() .beginTransaction(); switch (position) { case 0: ft.replace(R.id.standardLayout, new BalanceFragment(), tabNames[position]); break; case 1: ft.replace(R.id.standardLayout, new MyTradeFragment(), tabNames[position]); break; case 2: ft.replace(R.id.standardLayout, new MyTransFragment(), tabNames[position]); break; } ft.commit(); previousPosition = position; return true; } }; actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener); }
@Override public void onCreate(Bundle savedState) { super.onCreate(savedState); mSavedState = savedState; setContentView(R.layout.activity_standard_fragment); actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.chat_tabs_names, R.layout.item_actionbar_spinner); ActionBar.OnNavigationListener mOnNavigationListener = new OnNavigationListener() { String[] tabNames = getResources().getStringArray( R.array.chat_tabs_names); @Override public boolean onNavigationItemSelected(int position, long rowId) { if (mSavedState != null) { int savedPosition = mSavedState.getInt( BUNDLE_POSITION_NAME, Integer.MIN_VALUE); if (savedPosition != Integer.MIN_VALUE) { mSavedState.putInt(BUNDLE_POSITION_NAME, Integer.MIN_VALUE); actionBar.setSelectedNavigationItem(savedPosition); return false; } else { if (previousPosition == position) { return false; } } } FragmentTransaction ft = getSupportFragmentManager() .beginTransaction(); switch (position) { case 0: ft.replace(R.id.standardLayout, new ChatFragment(), tabNames[position]); break; case 1: ft.replace(R.id.standardLayout, new NewsFragment(), tabNames[position]); break; } ft.commit(); previousPosition = position; return true; } }; actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener); }
@Override public void onCreate(Bundle savedState) { super.onCreate(savedState); mSavedState = savedState; setContentView(R.layout.activity_standard_fragment); actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.profile_tabs_names, R.layout.item_actionbar_spinner); ActionBar.OnNavigationListener mOnNavigationListener = new OnNavigationListener() { String[] tabNames = getResources().getStringArray( R.array.profile_tabs_names); @Override public boolean onNavigationItemSelected(int position, long rowId) { if (mSavedState != null) { int savedPosition = mSavedState.getInt( BUNDLE_POSITION_NAME, Integer.MIN_VALUE); if (savedPosition != Integer.MIN_VALUE) { mSavedState.putInt(BUNDLE_POSITION_NAME, Integer.MIN_VALUE); actionBar.setSelectedNavigationItem(savedPosition); return false; } else { if (previousPosition == position) { return false; } } } FragmentTransaction ft = getSupportFragmentManager() .beginTransaction(); switch (position) { case 0: ft.replace(R.id.standardLayout, new AddProfileFragment(), tabNames[position]); break; case 1: ft.replace(R.id.standardLayout, new SelectProfileFragment(), tabNames[position]); break; } ft.commit(); previousPosition = position; return true; } }; actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener); }
@Override public void onCreate(Bundle savedState) { super.onCreate(savedState); mSavedState = savedState; setContentView(R.layout.activity_standard_fragment); fragmentManager = getSupportFragmentManager(); actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.ticker_tabs_names, R.layout.item_actionbar_spinner); ActionBar.OnNavigationListener mOnNavigationListener = new OnNavigationListener() { String[] tabNames = getResources().getStringArray( R.array.ticker_tabs_names); @Override public boolean onNavigationItemSelected(int position, long rowId) { if (mSavedState != null) { int savedPosition = mSavedState.getInt( BUNDLE_POSITION_NAME, Integer.MIN_VALUE); if (savedPosition != Integer.MIN_VALUE) { mSavedState.putInt(BUNDLE_POSITION_NAME, Integer.MIN_VALUE); actionBar.setSelectedNavigationItem(savedPosition); return false; } else { if (previousPosition == position) { return false; } } } FragmentTransaction ft = fragmentManager.beginTransaction(); switch (position) { case 0: ft.replace(R.id.standardLayout, new TickerFragment(), tabNames[position]); break; case 1: ft.replace(R.id.standardLayout, new OrdersFragment(), tabNames[position]); break; case 2: ft.replace(R.id.standardLayout, new TradesFragment(), tabNames[position]); break; } ft.commit(); previousPosition = position; return true; } }; actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener); }
@Override public void onCreate(Bundle savedState) { super.onCreate(savedState); mSavedState = savedState; setContentView(R.layout.activity_standard_fragment); actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.assist_tabs_names, R.layout.item_actionbar_spinner); ActionBar.OnNavigationListener mOnNavigationListener = new OnNavigationListener() { String[] tabNames = getResources().getStringArray( R.array.assist_tabs_names); @Override public boolean onNavigationItemSelected(int position, long rowId) { if (mSavedState != null) { int savedPosition = mSavedState.getInt( BUNDLE_POSITION_NAME, Integer.MIN_VALUE); if (savedPosition != Integer.MIN_VALUE) { mSavedState.putInt(BUNDLE_POSITION_NAME, Integer.MIN_VALUE); actionBar.setSelectedNavigationItem(savedPosition); return false; } else { if (previousPosition == position) { return false; } } } FragmentTransaction ft = getSupportFragmentManager() .beginTransaction(); switch (position) { case 0: ft.replace(R.id.standardLayout, new AssistAlarmFragment(), tabNames[position]); break; case 1: ft.replace(R.id.standardLayout, new AssistTasksFragment(), tabNames[position]); break; } ft.commit(); previousPosition = position; return true; } }; actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener); }
public void setCallback(OnNavigationListener callback) { mCallback = callback; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_reality_check); mActionBar = getSupportActionBar(); mActionBar.setDisplayHomeAsUpEnabled(true); mActionBar.setDisplayShowTitleEnabled(false); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); final String[] dropdownValues = getResources().getStringArray(R.array.reality_check_items_array);; // Specify a SpinnerAdapter to populate the dropdown list. ArrayAdapter<String> adapter = new ArrayAdapter<String>(mActionBar.getThemedContext(), android.R.layout.simple_spinner_item, android.R.id.text1, dropdownValues); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Set up the dropdown list navigation in the action bar. mActionBar.setListNavigationCallbacks(adapter, new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int position, long itemId) { switch (position) { case 0: RealityCheckListAdapter stepListAdapter = new RealityCheckListAdapter(RealityCheckActivity.this, R.layout.list_item_step_reality_check, mProcedure.getSteps()); mListView.setAdapter(stepListAdapter); break; case 1: CompareListAdapter step1ListAdapter = new CompareListAdapter(RealityCheckActivity.this, R.layout.list_item_step_compare, mProcedure.getSteps()); mListView.setAdapter(step1ListAdapter); break; } return true; } }); mProcedure = getIntent().getParcelableExtra("procedure"); mListView = (ListView) findViewById(R.id.listView); }
private void setupActionBar() { // Set up the action bar to show a dropdown list. final ActionBar actionBar = ((MainActivity) getActivity()) .getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); // Specify a SpinnerAdapter to populate the dropdown list. mDropDownAdapter = new DropDrownProjectsListAdapter( actionBar.getThemedContext(), android.R.layout.simple_spinner_item, mInfoToLoadAtDropDownListOfActionBar); OnNavigationListener listener = new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int position, long id) { // When the Navigation mode is activated, the source of // DropDownList (mInfoToLoadAtDropDownListOfActionBar) is empty, // because it is populate in an asynctask. // This condition must be check to avoid error. if (isDropDownListLoaded()) { mProjectIdToFilter = mInfoToLoadAtDropDownListOfActionBar .get(position).projectId; mLoadDataInListViewAsyncTask = new LoadDataInListViewAsyncTask(); mLoadDataInListViewAsyncTask.execute(mProjectIdToFilter, Application .getTaskPriorityFilterValue(getActivity())); } return true; } }; // Set up the dropdown list navigation in the action bar. actionBar.setListNavigationCallbacks(mDropDownAdapter, listener); // use getActionBar().getThemedContext() to ensure // that the text color is always appropriate for the action bar // background rather than the activity background. }