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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:36:09+00:00 2026-05-26T16:36:09+00:00

This should be so much simpler! I have an array of JSON objects that

  • 0

This should be so much simpler!

I have an array of JSON objects that I populate a spinner with, the whole projects works fine if I populate the spinner with the name and value pairs but it looks bad. If I populate the spinner with just the name I lose the value. From what I can tell from reading, the only way to do this is to populate the spinner with the name, retrieve the position of the selection then go back to the array to find the value of the name in the same position as it was in the spinner, is that how it has to work??

If so how do I do that?

Here is the code to popultate the spinner,

myUsers = jsonResponse.getJSONArray("GetBusinessNamesResult");

ArrayAdapter<String> adapter = new ArrayAdapter<String>(PropertyManagement.this, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

for (int i = 0; i < myUsers.length(); ++i)
{
    try {

        adapter.add(myUsers.getJSONObject(i).getString("BusinessName"));  

    } catch (JSONException e) {
        e.printStackTrace();
    }                   
}

Then down in my onItemSelected method, I think I have the original array in parent but I’m not sure! It is sent in as a parameter via AdapterView < ? > parent, which is code I got from a tutorial and I’m not sure what happens here.

String jsonStr = parent.getItemAtPosition(pos).toString();

So just looking at the code above, I think I have the original array and the position, or I may just have the selected name, in which case this isn’t going to work and should maybe be looking back up at myUsers???

The name value pairs are BusinessName and BusinessPhone. Do you think I can get what I need from that?

Cheers,

Mike.

  • 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-26T16:36:10+00:00Added an answer on May 26, 2026 at 4:36 pm

    Subclass BaseAdapter and use it in place of your ArrayAdapter.

    Here is an example:

    public class BaseAdapterWithHiddenValue extends BaseAdapter {
    
        public static class Entry {
    
            public String name;
            public String value;
        }
    
        List<Entry> items = new LinkedList<Entry>();
    
        public void add(String name, String value) {
            Entry e = new Entry();
            e.name = name;
            e.value = value;
            items.add(e);
        }
    
        @Override
        public int getCount() {
            return items.size();
        }
    
        @Override
        public Entry getItem(int arg0) {
            return items.get(arg0);
        }
    
        @Override
        public long getItemId(int arg0) {
            return 0;
        }
    
        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {
            // TODO: I'm lazy, create individual list entry view here
            return null;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This feels like it should be pretty simple, but not much seems to be
How can I optimize this query? It seems there should be a much easier
Should I always be using this method when rendering? Does it slow down much
This should be fine seeing as the CLR hasn't actually changed? The boxes running
This should be straight forward for a guru. I don't have any code really
First, apologies,this should be simple but I've had too much coffee and cannot wrap
In one of my Java 6 projects I have an array of LinkedHashMap instances
I've not used much Ajax before, and this seems simple. I have the seperate
I'm trying to retrieve data from a JSON object that looks like this: stdClass
I know this is a really simple thing that I really should know but

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.