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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:16:53+00:00 2026-06-03T01:16:53+00:00

I have a problem with spinner in android, I cant set enum values to

  • 0

I have a problem with spinner in android, I cant set enum values to its content. Here is code of spinner :

<Spinner
    android:id="@+id/spTrainingType"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:entries="@attr/TrainingType"
    android:prompt="@string/hint_training_type" />

And here is enum :

<declare-styleable name="TrainingStyle">
    <attr name="RecallType">
        <enum name="Vibro" value="1" />
        <enum name="Music" value="2" />
        <enum name="Silent" value="3" />
        <enum name="Alarm" value="4" />
    </attr>
    <attr name="RepeatType">
        <enum name="Daily" value="1" />
        <enum name="Weekly" value="2" />
        <enum name="Monthly" value="3" />
    </attr>
    <attr name="TrainingType">
        <enum name="Jogging" value="1" />
        <enum name="Cross" value="2" />
        <enum name="Climbing" value="3" />
        <enum name="BikeTrip" value="4" />
    </attr>
</declare-styleable>

So is there any way to put enums to spinner, or only arrays? Or may be i’m doing smth wrong.
Thanks in advance.

  • 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-03T01:16:54+00:00Added an answer on June 3, 2026 at 1:16 am

    As far as I know, what you’re trying to do isn’t possible in its current form. The attr namespace is meant to house ‘attributes’ for View(Group)s/Widgets etc, not values – hence the abbreviation. If you think about it for a second, if this were supported, there probably would’ve been something like a getEnumeration() method in the Resources class, or potentially a more generic version for mapping values into a… well, Map.

    The standard approach to making key/value pairs work with a Spinner, is to define separate arrays for the keys and values in res/values/arrays.xml. Items in such an array are loaded in-order, so you can use index-based lookups to match keys against values (and vice versa).

    An alternative approach, which I’m sure you’ll find suggested if you search around a little bit, is to merge the key and value into a single string; e.g. by using a special delimiter character, but this probably means you’ll need to pre-process it before displaying it to the user. It’s not the most flexible solution and definitely not what I’d prefer.

    That being said, it’s not too hard to implement your own XmlPullParser to load key/value pairs from a resource/xml file. If you follow that link to the class documentation, you’ll actually find a very basic implementation given for free. 🙂

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

Sidebar

Related Questions

i have a problem with my scrollview... my xml: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=wrap_content android:layout_height=wrap_content>
I have a problem on Android Spinner.In my application I created two Spinner on
I have a problem like I had a Spinner containing the Names of all
i have problem with autorotate on iphone i set up in all classes -
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I'm abit new to programming Android App's, however I have come across a problem,
I have a Spinner with an ArrayAdapter that feeds Values into it. The layout
I have an android spinner that's populated by a list of strings using an
I have a problem with back button functionality in an Activity of Android. The
I do have a problem with IToolbarManager. I have added a combo & 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.