refreshing the action bar spinner after database changes
I have an action bar spinner in one activity that gets populated using
data from a database. I have a second activity that modifies the database
(including data for the action bar spinner that is used in the first
activity). How do I refresh the spinner once database changes ? I tried
notifyDataSetChanged();, doesn't work. Also when I restart the app after
doing the changes, they are reflected in the spinner so I can see
modifying works, but only when I run the app again, not as the changes are
being made
// this is inside the onCreate()
// return a List<String> used to populate action bar spinner
listUniqueCat = mDbHelper.getUniqueCategories();
// create an array adapter to popluate dropdown list
adapter = new ArrayAdapter<String>(
getBaseContext(),
android.R.layout.simple_spinner_dropdown_item, listUniqueCat);
// enable dropdown list naaavigation in action bar
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
// defining navigation listiner
ActionBar.OnNavigationListener navigationListener = new
OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition,
long itemId) {
selectedPos = getActionBar().getSelectedNavigationIndex();
selectedSpinnerItem = listUniqueCat.get(selectedPos);
Toast.makeText(getBaseContext(),
"you selected " + selectedSpinnerItem,
Toast.LENGTH_LONG).show();
return false;
}
};
// setting dropdown items and item navigation listener for action bar
getActionBar().setListNavigationCallbacks(adapter, navigationListener);
No comments:
Post a Comment