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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:46:19+00:00 2026-05-18T04:46:19+00:00

I am trying to get a Spinner to work in Android. It displays fine

  • 0

I am trying to get a Spinner to work in Android. It displays fine and I can select any one of the options in the list. But how do I transfer that to a string?
I would have thought in the code below that ‘selected’ would hold the selected string, but I get an ‘Illegal modifier for the local class YourItemSelectedListener; only abstract or final is permitted’ error on the ‘YourItemSelectedListener’.
What am I doing wrong?
Many thanks for any help.

Spinner spinnerFPS = (Spinner) findViewById(R.id.sp_FPS);
        ArrayAdapter adapter = ArrayAdapter.createFromResource(
                this, R.array.framesps, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerFPS.setAdapter(adapter);
        spinnerFPS.setOnItemSelectedListener(new YourItemSelectedListener());


        public class YourItemSelectedListener implements OnItemSelectedListener {

            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                String selected = parent.getItemAtPosition(pos).toString();
            }

            public void onNothingSelected(AdapterView parent) {
                // Do nothing.
            }
        }
  • 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-18T04:46:19+00:00Added an answer on May 18, 2026 at 4:46 am

    Since you are using an array resource for spinner create a resource handle
    with local array declaration with getResources().getStringArray(R.array.framesps);

    and then use that handle to access the selected item using position variable:

    items[pos]
    

    Heres a code edit:

    Spinner spinnerFPS = (Spinner) findViewById(R.id.sp_FPS);
        String[] items=getResources().getStringArray(R.array.framesps);//handle to your arrays
    ArrayAdapter adapter = ArrayAdapter.createFromResource(
                this, items, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerFPS.setAdapter(adapter);
        spinnerFPS.setOnItemSelectedListener(new YourItemSelectedListener());
    
    
        public class YourItemSelectedListener implements OnItemSelectedListener {
    
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                String selected =items[pos]; // use handler to access select item
            }
    
            public void onNothingSelected(AdapterView parent) {
                // Do nothing.
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a spinner list where my users can select a
I'm trying to save a Spinner value into a ListPreference. I can't get it
I'm trying to get my spinneradapter working. I get no error's but the spinner
currently i'm trying to get a custom spinner to work. It uses a custom
I'm trying to get my spinner working as the Action Bar Drop Down List
In Android, I am trying to get the selected Spinner value with a listener.
I'm trying to use the following to create a Spinner . But I get
I'm trying to get an onClickListener to fire on a Spinner, but I get
I am trying to get the selected items string out of a Spinner .
Trying to get an ASP application deployed; it worked for a while but then

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.