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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:48:05+00:00 2026-05-16T04:48:05+00:00

I have a custom spinner (customized for formatting). It works fine and shows the

  • 0

I have a custom spinner (customized for formatting). It works fine and shows the result of the selected array item. The string array with my data is called mydata[].

I want to do something with that result – I’ve tried hours of changes but, it seems I don’t know what the container is for the selected result – it just displays automatically. The mNumber refers to a case select in a class (it’s result is based on what’s passed into-it).

My question(s) – refer to the * WHAT DO I USE HERE * shown in the code’s last line:
1. What is the container for the result?
2. How to access and syntax it?

Here’s the code:
Thank you!

**[declared in onCreate]**  
    Spinner spinner = (Spinner) findViewById(R.id.Spinner01);    
    MySpinnerAdapter adapter = new MySpinnerAdapter(this, R.layout.mspinner, R.id.text,mydata);   
    spinner.setAdapter(adapter);  

**[declared outside of onCreate]**  
    @SuppressWarnings("unchecked")  
    private class MySpinnerAdapter extends ArrayAdapter{  
    public MySpinnerAdapter(Context context, int resource, int textViewResourceId, String[] objects) {  
    super(context, resource, textViewResourceId, objects);  
    final TextView woof =(TextView)findViewById(R.id.TextView07);  
    woof.setText(String.valueOf(dogday.mNumber(*** WHAT DO I USE HERE ? ***)));  
    }  
    }  

EDITED – FOR MY RESPONSE TO COMMONSWARE (too many characters for a comment box).

Thanks. You know the result that gets displayed in a spinner (by default) when something’s selected – that’s the piece of data I need. I want to use it as an argument for a call.

The user selects something in the spinner – The selected item will be used to make some choices in the class method (dogDay), which takes a data argument for mNumber(data) and returns a result (just like a function).

I want to do some math calcs with the result. First, I want to display what’s coming back (for now) so, I’m using the dogDay.mNumber(data) as an argument for woof.text.

My question is this, How to get the piece of data (the thing the user selected in the Spinner)? How did the spinner know what to display for my selection – that’s what I want? I tried using something like getSelectedItem (or whatever the it was – I can’t remember just now) but, it crashes.

Is their an easier way to custom format a spinner? (and get the data) I searched hi and low for info and found only one applicable to android 1.5/later (I want a spinner with all black background and red text – I can do it via the way shown in my code using a the custom layout).

Thanks – I got a bit long winded!

EDITED – with full code
Here’s a full code with the custom spinner and the call you suggested. As I mentioned, I already tried it – it only shows the first item in the list – never the selected one. I use the result of getSelectedItem as an argument for the string… I tried it from both within and outside the adapter…

package com.bt.junk;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class MyMaincode extends Activity {
private static String mydata[] = {"one", "two", "three"};

int poop;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
// DECLARATIONS ------------------------------------------------       
    Spinner spinner = (Spinner) findViewById(R.id.Spinner01);

    MySpinnerAdapter adapter = new MySpinnerAdapter(
        this,R.layout.custom_spinner_row,R.id.text, mydata );

    spinner.setAdapter( adapter );

    poop = spinner.getSelectedItemPosition();

}//end onCreate ********************************************

// METHODS, CLASSES, etc ---------------------------------------
@SuppressWarnings("unchecked") //<-- I added that
private class MySpinnerAdapter extends ArrayAdapter{
    public MySpinnerAdapter(Context context, int resource,
                   int textViewResourceId, String[] objects) {
        super(context, resource, textViewResourceId, objects);                  

        final TextView sayWhat = (TextView) findViewById(
                                            R.id.TextView01);
        sayWhat.setText(String.valueOf(mydata[poop]));

    }//end MySpinnerAdapter
}//end class MySpinnerAdapter
}//end activity
  • 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-16T04:48:06+00:00Added an answer on May 16, 2026 at 4:48 am

    Your question makes little sense to me. I am assuming that “I want to do something with that result” means “I want to find out the selected item’s position in the array”. If that assumption is correct, you can get the selected position for a Spinner by calling getSelectedItemPosition(). This will be 0 when the Spinner first appears, unless you change the position yourself.

    Your code is also very strange, IMHO. The constructor of an ArrayAdapter should not be attempting to manipulate a widget.

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

Sidebar

Related Questions

I have a custom 9-patch image for my spinner. This image works fine on
I have custom drupal module. I receive result from a webservice that I need
I have custom SiteMapProvider and RoleProvider that works together properly: IsAccessibleToUser returns false if
I have a custom spinner that uses two custom views, one for the drop
I have custom js/jquery code which is running fine on all browsers including IE9
I have a custom View class that extends Spinner. I'm trying to figure out
I have a spinner with a custom adapter displaying objects from a database. When
I have created a custom Array Adapter to bind a custom row that contains
I have a custom spinner dropdown xml file in /res/layout/: spinner_view_dropdown.xml: <?xml version=1.0 encoding=UTF-8?>
I've created a custom adapter for my spinner because I wanted to have multiple

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.