/** * Updates the action bar navigation list selection to that of the current account whose * transactions are being displayed/manipulated */ public void updateNavigationSelection() { // set the selected item in the spinner int i = 0; Cursor accountsCursor = mAccountsDbAdapter.fetchAllRecordsOrderedByFullName(); while (accountsCursor.moveToNext()) { long id = accountsCursor.getLong(DatabaseAdapter.COLUMN_ROW_ID); if (mAccountId == id) { getSupportActionBar().setSelectedNavigationItem(i); break; } ++i; } accountsCursor.close(); }
/** Set up action bar navigation list and listener callbacks */ private void setupActionBarNavigation() { // set up spinner adapter for navigation list Cursor accountsCursor = mAccountsDbAdapter.fetchAllRecordsOrderedByFullName(); SpinnerAdapter mSpinnerAdapter = new QualifiedAccountNameCursorAdapter( getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_item, accountsCursor); ((ResourceCursorAdapter) mSpinnerAdapter) .setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks(mSpinnerAdapter, mTransactionListNavigationListener); actionBar.setDisplayHomeAsUpEnabled(true); updateNavigationSelection(); }