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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:59:56+00:00 2026-06-09T13:59:56+00:00

How do you fill a spinner from java code programmatically? I have a spinner

  • 0

How do you fill a spinner from java code programmatically?

I have a spinner in the layout like this:

 <Spinner
     android:id="@+id/consultation_deseases"
     android:layout_width="@dimen/bigSpinnerWidth"
     android:layout_height="@dimen/bigSpinnerHeight"
     android:prompt="@string/disease_prompt" />

With java code I need to create the adapter and add the items.

  • 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-09T13:59:58+00:00Added an answer on June 9, 2026 at 1:59 pm
    // you need to have a list of data that you want the spinner to display
    List<String> spinnerArray =  new ArrayList<String>();
    spinnerArray.add("item1");
    spinnerArray.add("item2");
    
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(
        this, android.R.layout.simple_spinner_item, spinnerArray);
    
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Spinner sItems = (Spinner) findViewById(R.id.spinner1);
    sItems.setAdapter(adapter);
    

    also to find out what is selected you could do something like this

    String selected = sItems.getSelectedItem().toString();
    if (selected.equals("what ever the option was")) {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to make spinner to fill empty place in left side? android:layout_width=fill_parent does not
I have an Android application with a Spinner and want to fill it dynamically
i have created following layout. <TableLayout android:layout_width=fill_parent android:layout_height=wrap_content android:orientation=horizontal > <TableRow> <TextView android:layout_width=fill_parent android:layout_height=wrap_content
I have a simple Android Spinner which I fill with a two column list
Hi i have an android spinner populated from and array that i want to
I have a tablelayout in Android like this: 1) Row == IMAGEVIEW | TEXTVIEW
I am new in android. I need to fill the spinner from SQLite database.
All- I have a layout that looks like this: My goal is to have
I have a Spinner with an ArrayAdapter that feeds Values into it. The layout
I'd really like my app to have a Spinner which stretches the entire length

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.