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 3970160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:03:11+00:00 2026-05-20T04:03:11+00:00

I have an android spinner item, in which the lines are made up of

  • 0

I have an android spinner item, in which the lines are made up of a TextView and an ImageView (a star, to mark that the user has marked that particular item as a favourite). Now, when a user favourites an item, I want to make the star appear next to that item in the spinner list, so I want to redraw the spinner to show the updated images. How do I do this?

What I’m doing now is that I’m creating a whole new spinner, with the appropriate images. This makes my spinner set the selected item to the first item in the list, which is annoying – I want it to stay the same. I have tried

spinner.setSelection(selectedItem);

This works for ANY number other than the number I actually want (the position of the currently selected item), then it sets the selected spinner item to the first in the list again.

So: how can I redraw the list with the updated information without having to recreate the whole list, or alternatively, how can I recreate the list and still preserve the spinner item selection?

To clarify: here’s what I’m doing

// Callback for "favourite"-button
star.setOnClickListener(new ImageButton.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // Toggle favourite
            getActiveSelection().setStarred(getActiveSelection().isStarred() ? false : true);
            reloadText();
            createSpinner();
        }
    });

 private void createSpinner() {

    spinner = ((Spinner)findViewById(R.id.spinner));

    ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
    HashMap<String, Object> map = new HashMap<String, Object>();

    // Populate spinner item list
    for(int i=0; i<N; i++) {
        SpinnerItem item = getSpinnerItem(i);
        map = new HashMap<String, Object>();
        map.put("Name", item.getName());
        map.put("Icon", (item.isStarred() ? "On" : "Off"));
        list.add(map);
    }        

    MySpinnerAdapter aspn = new MySpinnerAdapter(this, list,
            R.layout.spinner, new String[] { "Name", "Icon" },
            new int[] { R.id.spinnerrow, R.id.spinnerrowicon });


    spinner.setAdapter(aspn);
    spinner.setSelection(getActiveSelection().getSpinnerPosition());
}
  • 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-20T04:03:11+00:00Added an answer on May 20, 2026 at 4:03 am

    You may just update spinner adapter – let it know which item is starred when user clicks on the star icon (star.setOnClickListener…). What I would do:

    1. In adapter construction, you pass only list of “Name” fields, no need for icon (all not starred by default)
    2. You add separate function to adapter to set starred item (setStarred(String name))
    3. On initial call, invoke setStarred to set initial selection (if any)
    4. in star.setOnClickListener implementation, call setStarred for starred item on adapter which you obtain as (MySpinnerAdapter)spinner.getAdapter()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a Spinner that initially (when the user has not made
I have an android spinner that's populated by a list of strings using an
I have a spinner, which mostly works. If a user selects one of the
Hello I have question about android spinner I have spinner which is populated by
Hello I have question about android spinner I have spinner which is populated by
I have an Android Spinner view in my layout. I would like that spinner
I have an android spinner which I call via the performClick method to show
I have an Android Spinner widget in which I'd like to display a slightly
I have Android pet-project DroidIn which utilizes HttpClient 4 (built into Android) to do
I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how

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.