I have a view with a counter. This activity launches another acquitability with a pop-up window where I add or remove values ββthat the parent displays in Spinner. Thus, in onActivityResult (), I update the contents of Spinner so that it reflects any additional or deleted values ββby calling the fillSpinner () method. The parameter of this method is the previously selected value:
private void fillSpinner(String value){ Cursor c = mDbHelper.getAllCategories(); startManagingCursor(c); c.moveToFirst(); String[] from = new String[]{DBAdapter.KEY_CATEGORY}; SimpleCursorAdapter scCats = new SimpleCursorAdapter( this, android.R.layout.simple_spinner_item,c,from, new int[]{android.R.id.text1}); scCats.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item); category.setAdapter(scCats); if (value != null && value != "") { category.setSelection((int)mDbHelper.categoryIndex(value)); } }
When I open Spinner, it contains the correct list (that is, it has been updated) and the correct value is selected. However, the Spinner control itself (in the closed state) does not display the selected value, but the first in the list.
When I look at the code in the debugger, the Spinner value is correct before and after calling setSelection () (and it is always called with the same valid id). However, since I cannot exit the event when I resume execution after a short moment, the value in Spinner changes.
In other words, the line with the counter reading changes and differs from the selected item when I return from my pop-up activity.
Any ideas are welcome.
android android-activity spinner
cdonner
source share