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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:39:15+00:00 2026-05-27T08:39:15+00:00

I have created a Spinner and ArrayAdapter as follows: Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);

  • 0

I have created a Spinner and ArrayAdapter as follows:

Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
final ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(
            this, R.array.units_array1, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);

The units_array1 is a string array declared in a xml file like this:

<string-array name="units_array1">
    <item>Centimeters</item>
    <item>Meters</item>
    <item>Kilometers</item>
    <item>Inches</item>
    <item>Foots</item>
    <item>Miles</item>
</string-array>

Now I want to implement some If-ELSE conditions that are based on the elements in string-array. I Have researched a lot on the internet for this but haven’t found out any solution that works. Please help me in implementing a function that returns the individual elements from the string-array using the adapter.

  • 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-27T08:39:16+00:00Added an answer on May 27, 2026 at 8:39 am
    spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View v, int position, long id3) {
            final String scale = adapter1.getItem(position);
            // scale is gonna be "Centimeters" or "Meters", etc...
            if (scale.equals("Centimeters")) {
                // do something
            } else if (scale.equals("Meters")) {
                // do something else 
            }
        }
    
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my spinner's code: Spinner food = (Spinner) findViewById(R.id.spinner1); ArrayAdapter<CharSequence> foodadapter = ArrayAdapter.createFromResource(
In my Android app, I have an Activity with a Spinner widget. I created
I have a problem on Android Spinner.In my application I created two Spinner on
I have created an application for ContactsContract... I have created a spinner which brings
I created an app and have been testing it against targetSdk 14. The spinner
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a spinner with 3 options: Beginner, Advanced and Pro. When one
i have created a spinner.could i place my spinner items in a table into
I have created a Spinner that is populated with an ArrayList . I want
I have an Android Spinner view in my layout. I would like that spinner

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.