Hi, I think i found the solution: a call to ArrayAdapter<CharSequence>.notifyDataSetChanged fixed the problem.
Thierry. 2010/2/3 Thierry Legras <tleg...@gmail.com> > Hi, > > I saw several people reporting an issue with Spinner.setSelection that does > not seem to work as expected on the second call: the item selection is > correctly updated in the list subframe, but not in the text displayed when > the spinner is closed > > Anbody knows a workarround? > > Thierry. > > > > On 4 juin 2009, 21:46, Ben Roberts <divestocl...@gmail.com> wrote: > > There are at least two other people who have encountered this problem: > http://groups.google.com/group/android-beginners/browse_thread/thread...http://groups.google.com/group/android-developers/browse_thread/threa. > .. > > > > Any ideas? Is it a bug? > > > > At the very least, does anyone know of an open source app that uses a > > Spinner on a layout from which another Activity can be launched? > > > > On Jun 1, 9:17 pm, Ben Roberts <divestocl...@gmail.com> wrote: > > > > > I'm quoting an old message from last year because it's EXACTLY the > > > problem I'm having: > > > > > > Hi all, > > > > I have a spinner in a dialog. Calling spinner.setSelection(int) > > > > correctly sets the spinner just after opening the app. If I reopen > the > > > > dialog after making another spinner.setSelection(int) call, the > > > > spinner shows the first item regardless of the selection being set, > > > > BUT... > > > > > > clicking on the spinner shows that the correct value is selected in > > > > the list of options (green dot next to the item). Weird huh? > Sometimes > > > > when this happens, the spinner is cutting off parts of the text. Has > > > > anyone else seen this happen? > > > > > Since the last guy got no response, I'll give as much detail as I > > > can... this is driving me nuts. > > > > > I built a class to help me build a Spinner in a consistent manner to > > > display a list of categories. After the objects are initialized, my > > > Activity calls a method initCatSpinner which builds the ArrayAdapter > > > and finishes initializing my Spinner. > > > > > Called from onCreate and onActivityResult: > > > mCategorySpinner = mCatSpinHelper.initCatSpinner(mCategoryId, > > > catcursor); > > > > > public Spinner initCatSpinner(long initial_category, Cursor > > > all_categories) { > > > LinkedList<CategorySpinnerItem> categories = new > > > LinkedList<CategorySpinnerItem>(); > > > > > // Code to build this linked list from all_Categories is here, > > > removed for brevity > > > // Code adds an "All" item to the top, builds a list of > categories > > > using catcursor, then adds a "Edit Categories" option to the end of > > > the list > > > > > if(initial_category == ID_ALL) { > > > mLastCategoryPosition=0; > > > } > > > > > // Build the spinner adapter and set up the Spinner > > > ArrayAdapter<CategorySpinnerItem> spinadapter = new > > > ArrayAdapter<CategorySpinnerItem>(mCtx, > > > android.R.layout.simple_spinner_item, > > > android.R.id.text1, > > > categories); > > > > > spinadapter.setDropDownViewResource > > > (android.R.layout.simple_spinner_dropdown_item); > > > mCatSpinner.setAdapter(spinadapter); > > > mCatSpinner.setSelection(mLastCategoryPosition); > > > mCatSpinner.setPrompt(mCtx.getResources().getString > > > (R.string.choose_category)); > > > > > return mCatSpinner; > > > > > } > > > > > This works fine on two different activities when they are launched. > > > One activity launches to show a list of all items in the category > > > chosen by this spinner. From there I can launch another activity in a > > > dialog to change the category of a selected item, and when I do this > > > and return to the original activity I get the above symptoms. I still > > > see a list of the items in the proper category, if I open the spinner > > > the category that was originally selected is still selected, but the > > > spinner item that's displayed on the widget itself is always the first > > > one in the list! It also happens if I switch to another Activity then > > > come back to this one. > > > > > I've checked with Log output and mLastCategoryPosition IS being set > > > correctly, so the setSelection call is passing the right data. I even > > > tried calling SystemClock.sleep for a few hundred milliseconds > > > thinking it might be a race condition, with no change. What's going on > > > here? I'm using the 1.5r2 SDK. > > -- > Thierry. > -- Thierry. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en