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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:32:38+00:00 2026-05-20T17:32:38+00:00

I have an Android application which retrieves from a external server, a name and

  • 0

I have an Android application which retrieves from a external server, a name and a corresponding ID (this could be 1 name and ID combo or multiple name ID combinations), these are all stored in a HashMap<String, String> – The ID as the key and the Name as the value.

What I then would like to implement is a dynamic Spinner that populates itself with the ‘Names’ from this HashMap and when the user selects one of these names a setting somewhere I set to the ID number. This ID number will then be used in later server requests.

My question is what is the best way to implement this custom Spinner from the HashMap so that when the option is selected the ID number is set somewhere. This ID number has to be accessible from several activities – the spinner is present in several different activities… but should have the same effect on each screen.

Design patterns and pseudo code would be hugely appreciated. At the moment the Spinner is on 2 different screens, at the top below the ActionBar, but obviously the code is in both XML layout files.

Cheers.

EDIT

Code to set names and IDs in HashMap:

// Returns a Map of blog name to blog ID associated with the authenticated user
    public Map<String, String> extractBlogInfo(XMLDataExtracter blogData)
    {
        Log.d(TAG, "BlogOperations::extractBlogInfo()");

        ArrayList<String> blogIDs = new ArrayList<String>();
        ArrayList<String> blogNames = new ArrayList<String>();
        Map<String, String> blogIDNamePairs = new HashMap<String, String>();

        // Get ID and Names and store them in blogIDs and blogNames variables       


        if (blogIDs.size() == blogNames.size())
        {

            for(int i = 0; i < blogIDs.size(); i++)
            {
                blogIDNamePairs.put(blogIDs.get(i), blogNames.get(i));
            }
        }
        else
        {
            // An error occured
            Log.d(TAG,
                    "BlogOperations::extractBlogInfo() > An error occured - ID and Name array sizes do not match");
            return null;
        }

        return blogIDNamePairs;
    }
  • 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-20T17:32:39+00:00Added an answer on May 20, 2026 at 5:32 pm

    For this you can use Shared preference.. You get the Id of the selected value from spinner and stored it in shared preference..

    So that you can access this value any where inside your Apps..

    If you want to display the selected spinner value from Say Activity1 in Activity2 get the value from Shared preference, now it will be Id so get the corresponding Name from the Id in hash Map..

    For shared preference take a look at this… and this….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android application which grabs some data from an external XML source.
I have an Android application from which I want to upload some data to
I have an Android Application which uses JNI calls. Now i want this application
I have a android application which needs username and password to login. I need
Hello I have an android application which has a service running. After 20 mins
I have an Android application in which I have my preferences in an XML
I have an Android application which handles a particular type of file. It registers
I am creating an Android application which will have some embedded music inside of
I've created an Android application which has a certain package name that I've been
I am due to make an android application which sends and recieves data from

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.