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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:20:46+00:00 2026-06-11T07:20:46+00:00

I have been creating Spinner controls (Combo boxes/Drop downs) in one of my apps,

  • 0

I have been creating Spinner controls (Combo boxes/Drop downs) in one of my apps, and was surprised to find out how difficult it was to achieve all of the following features:

  1. User facing Strings are externalized, taking advantage of strings.xml internationalisation (I18N) feature of Android.
  2. Spinner selections operate using a System view, which facilitates not having to work with or map Strings to meaningful values (yuck).
  3. User view to System view mapping should be easy, automated and minimal (i.e not hand rolled for every component).

Others have attempted solutions to this, but universally as far as I could see they suffer from one or many of the following problems:

  1. UI code is creeping into their enum class which doesn’t belong there (messy), nearly all existing solutions suffered from this.
  2. Hardcoded User facing Strings in their enum classes. Because these are not externalized you cannot do I18N using the stock Android features.
  3. Authors typically make the Fragment or Activity an OnItemSelectedListener which perpetuates a common problem of inheritance for convenience, where composition is more appropriate.

I have developed my own solution which does this: http://www.androidanalyse.com/android-spinner-externalize-user-strings-mapped-to-system-enum/

My question is, have I missed something? This seems like something that should not have been this hard (which makes me feel like I’m possibly reinventing the wheel).

Below is some example code showing my solution in-use (which is available Apache 2 license from the link above).

String none = getString(R.string.none);
String light = getString(R.string.light);
String medium = getString(R.string.medium); 
String strong = getString(R.string.strong);
SpinnerUtil.createNewSpinner(view, R.id.wind, Arrays.asList(none, light, medium,     strong), WindLevel.values(),
  new SpinnerItemSelectedListener<WindLevel>() {
  public void onItemSelected(Spinner item, WindLevel value) {
    // Take whatever action you wish to here.
  }});
  • 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-11T07:20:48+00:00Added an answer on June 11, 2026 at 7:20 am

    I would just use ArrayAdapter<WindLevel>. Yes, you created a custom typed listener, but the regular event listener gets the position and can call getItem() on the ArrayAdapter<WindLevel> to get a WindLevel properly typed.

    IMHO, the vast majority of Spinner widgets will be populated with material read in from a database, the Internet, or some other dynamic data source, rather than populated by some sort of enum with display values coming from static strings that can be internationalized ahead of time.

    This is not to say that your code is useless: if you find it useful, then it was worth writing. And I am sure that there are apps out there that contain your targeted pattern (i.e., a Spinner backed by an enum or equivalent where the display values are known in advance and can be internationalized) who might find your solution useful as well. Every developer who writes enough code cooks up these sorts of helper classes and the like that help map an OS or framework model into something that better fits the developer’s own mental model. So long as you are not perceiving any performance issues, it’s all good.

    Also, note that OnItemSelectedListener is an interface; implementing that interface on an existing class is not inheritance.

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

Sidebar

Related Questions

I have been creating a Flash file where more than one MovieClip can be
I have been creating Unit tests like crazy and find that I'm often having
So far I have been creating Silverlight apps with all logic crunched into a
I have been creating Facebook apps for sometime now. I use the javascript SDK
I have been creating a gtk+ application in eclipse. At a point in the
I have been creating a peer to peer connection for a new game, that
I have been creating an image gallery with jQuery, all is done. The images
I have been creating an app for Android SDK 8 and it works fine.
So i have been creating this framework thing that basically puts together source code
So far I have been creating Web Portal but recently I had a request

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.