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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:17:23+00:00 2026-06-09T09:17:23+00:00

I have a spinner which contains dynamic data which is displayed over 2 lines.

  • 0

I have a spinner which contains dynamic data which is displayed over 2 lines. What I require help with is dislaying only part of the spinners value (ItemArrayName[i]) within the spinner text box.

To calrify in the popup when the spinner is clicked, I require the full text, however when the item has been select I only require the item name.

e.g.
Within the App:
Item Name

Within the spinner selection pop out:
Item Name
Atk = 10, Def = 10

Java Code:

ArrayList<String> ItemArrayList = new ArrayList<String>();  
for(int i = 0; i < ItemArrayName.length; i++)
{
    ItemArrayList.add(ItemArrayName[i] + "\nAtk = " + String.valueOf(ItemArrayAtk[i]) + ", Def = " + String.valueOf(ItemArrayDef[i]));
}

Spinner spnItem = (Spinner) view.findViewById(R.id.UseItem);
ArrayAdapter<String> adpItem = new ArrayAdapter<String> (context, R.layout.spinnerrow, ItemArrayList);
spnItem.setAdapter(adpItem);
spnItem.setOnItemSelectedListener(new OnItemSelectedListener() 
{   
    public void onItemSelected(AdapterView<?> parent, View view, int position, long arg3) 
    {
        //String city = "The item is " + parent.getItemAtPosition(position).toString();
        //Toast.makeText(parent.getContext(), city, Toast.LENGTH_LONG).show();
    }

    public void onNothingSelected(AdapterView<?> arg0)
    {
        // TODO Auto-generated method stub
    }
});

Thanks in advance

  • 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-06-09T09:17:25+00:00Added an answer on June 9, 2026 at 9:17 am

    How about using a Hashtable to map what you display in the spinner to your more detailed popup string?

    EDIT:
    Here’s a primitive and possibly non compiling modification to your code using a hashtable as described:

    // EDIT #1: Create a hashtable to lookup stuff:
    final Hashtable<String, String> vals = new Hashtable<String, String>();
    
          for(int i = 0; i < ItemArrayName.length; i++)
          {
             vals.put(ItemArrayName[i], ItemArrayName[i] + "\nAtk = " + String.valueOf(ItemArrayAtk[i]) + ", Def = " + String.valueOf(ItemArrayDef[i]));
          }
    
          Spinner spnItem = (Spinner) view.findViewById(R.id.UseItem);
          // EDIT #2: Extract the array of hash keys to show in your list:
          ArrayAdapter<String> adpItem = new ArrayAdapter<String> context, R.layout.spinnerrow, vals.keySet().toArray(new String[vals.size()]));
          spnItem.setAdapter(adpItem);
          spnItem.setOnItemSelectedListener(new OnItemSelectedListener()
          {
             public void onItemSelected(AdapterView<?> parent, View view, int position, long arg3)
             {
                // EDIT #3: retrieve the full string from the hashtable using "get":
                String city = "The item is " + vals.get(parent.getItemAtPosition(position).toString());
                //Toast.makeText(parent.getContext(), city, Toast.LENGTH_LONG).show();
             }
    
             public void onNothingSelected(AdapterView<?> arg0)
             {
                // TODO Auto-generated method stub
             }
          });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed part of an application which contains a number of spinners to
I have an xml layout file which contains a few widgets including a Spinner
Hi I have a spinner for which I would like to change its entry.
I have created an application for ContactsContract... I have created a spinner which brings
I have an activity with a spinner which loads a simpleCursorAdaptor. I call another
I have a spinner, which mostly works. If a user selects one of the
I have a spinner which is in the Emulator light gray with black text
I'd really like my app to have a Spinner which stretches the entire length
I got a Spinner element which I populate with data from a Cursor using
I have a Main-Activity which displays several spinners. With a Toggle-Button in the Main-Activity

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.