Okay, as I could not find a way to fix that smoothly, I just used a flag
ignoreNextOnItemSelected like described hereafter. Seems to me a dirty hack
:(

// called from another activity context
updateSpinnerSelection(int newposition) {

    mPosition = newposition; // store it
    mSpinner.setSelection(newposition);
    ignoreNextOnItemSelected= true;
}

and

public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
                long rowid) {
    if (ignoreNextOnItemSelected) {
        // position might be outdate ?!?! just reapply mPosition
        ignoreNextOnItemSelected = false;

        // required
        mSpinner.setSelection(mPosition);
    } else {
        mPosition = position;
        ... // do usual stuff
    }
}



2011/2/25 Thierry Legras <tleg...@gmail.com>

> Hi,
>
> I have a strange behavior in a very specific case and wonder if the issue
> comes from my code or not.
>
> I have a TabActivity A with 2 tabs:
> - Tab 1 content is created as a view with a spinner in it
> - Tab 2 content is an activity B.
>
> I want at some point when Tab2 is selected to switch to Tab 1 and update
> spinner selection in it.
>
> Case 1)
> Tab 2 is selected, from Activity B context:
>
> activityA.updateSpinnerSelection(newposition);
> activityA.getTabHost().setCurrentTabByTag(tab1tag);
>
> later AdapterView.OnItemSelectedListener.onItemSelected is called with my
> newposition
>
> => so this *usually *works fine:
>
> Case 2)
> Tab 2 is selected, from Activity B context, but before doing the same
> things, if the users for some reason *first open a new acticity C on top
> of B (like preference screen) and close this activity C*, (so A and B are
> paused then resumed), then if I later try again the same things:
>
> activityA.updateSpinnerSelection(newposition);
> activityA.getTabHost().setCurrentTabByTag(tab1tag);
>
> so far so goog, but later
> AdapterView.OnItemSelectedListener.onItemSelected is called not with
> newposition as argument *but with the older position value*.
>
>
> I hope the description is clear.
>
> Did I missed something? or could this behavior dues to some bug in Android?
>
>
> Thanks for any help,
> --
> 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

Reply via email to