Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:38:41+00:00 2026-05-29T04:38:41+00:00

I’m currently working on a Account Management Activity for my Android application and I’m

  • 0

I’m currently working on a Account Management Activity for my Android application and I’m having trouble figuring out why the setSelection() method from a spinner does not trigger the OnItemSelectedListener attached to said Spinner.

Here is what I have currently;

onCreate() method :

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_management);

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    retreiveLanguage();
    initializeUI();

    // Vérification si l'usager est déjà connecté
    Globals appState = ((Globals) this.getApplication());
    boolean userLoggedIn = appState.isUserLoggedIn();
    boolean userInfoAvailable = appState.isUserInfoAvailable();

    if (userLoggedIn && userInfoAvailable) {
      fillUI();
    }
}   

Pertinent lines from the initializeUI() method which is called on the Activity’s creation which shows the binding of the Spinner the Listener :

    /** OnItemSelectedHandler for the Country Spinner */
    mCountrySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View view,
                int pos, long id) {
            Log.i(TAG, "onCountrySelected() was called, position : " + pos);

            mProvinces = new ArrayList<String>();
            mProvincesCode = new ArrayList<String>();

            mXML.parseResponse(FileManager.getInstance().getPortalOptions());

            for (int i = 0; i < mXML.getCountry(pos).sizeProvinces(); i++){
                mProvinces.add(mXML.getCountry(pos).getProvince(i).getLabel(mLanguage));
                mProvincesCode.add(mXML.getCountry(pos).getProvince(i).getCode());
            }

            mProvinceArrayAdapter = new ArrayAdapter<String>(ManageAccountActivity.this, 
                    android.R.layout.simple_spinner_item, mProvinces);
            mProvinceArrayAdapter.setDropDownViewResource(
                    android.R.layout.simple_spinner_dropdown_item);
            mProvinceSpinner.setAdapter(mProvinceArrayAdapter);
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // Do Nothing ...               
        }
    });

And again another couple lines, this time from the fillUI method() :

Log.i(TAG, "Setting country based on user information.");
((Spinner) findViewById(R.id.spin_country))
    .setSelection(mCountriesCode.indexOf(mUser.getCountry()));
// TODO : Fix Provinces and States not being changed accordingly
Log.i(TAG, "Setting province based on user information.");
((Spinner) findViewById(R.id.spin_province))
    .setSelection(mProvincesCode.indexOf(mUser.getProvince())); 

So with this I would expect the OnItemSelectedListener to be called right after I set the selection in the fillUI() method, but that’s not what’s happening at runtime :S

Here’s my LogCat extract that shows that the Listener isn’t called when the selection is applied to the country spinner:

I/ManageAccountActivity(28108): Setting country based on user information.

I/ManageAccountActivity(28108): Setting province based on user information.

I/ManageAccountActivity(28108): onCountrySelected() was called, position : 1

As an experiment, I also tried putting the fillUI() call in the onStart method of my Activity but that didn’t change how the application reacted.

Thanks in advance for any pointers, help or tips !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:38:42+00:00Added an answer on May 29, 2026 at 4:38 am

    Have you tried to set the spinner by using two arguments, the second using a boolean:

    .setSelection(mProvincesCode.indexOf(mUser.getProvince()), true); 
    

    From the developers page it shows:

    setSelection(int position, boolean animate)
    //Jump directly to a specific item in the adapter data.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.