Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android create a spinner with items that have a hidden value and display some text?

Tags:

I'm sure this is asked plenty and i've found some questions on here similar but none really got the coin dropping for me. I'm hoping someone can help me out.

What I want to do is present the user with a dropdown (spinner) with a list of flavours Vanilla, Chocolate, Strawberry.

When the user selected the flavour of their choice the I want the value of Strawberry which is 10 to be returned.

Strawberry = 10
Chocolate = 20
Vanilla = 30

I come from a vb.net background so finding this incredibly hard to work with the fact i need arrayadapters and stuff to do it?

Could anyone simplify things for me and perhaps share some code?

like image 672
L2wis Avatar asked Jul 05 '12 11:07

L2wis


People also ask

How do I hide spinner text?

You can hide spinner in the ProgressButton by setting the e-hide-spinner property to cssClass . Is this page helpful?

How can I use more than one spinner in Android?

Clearly each of your adapters need to adapt a different set of String s, so you need to create an ArrayAdapter for each Spinner . A single OnItemSelectedListener will work for the 3 Spinners (as long as you set them). You can call getId() on the AdapterView<?>

How can I make my spinner look like Edittext?

Here is an workaround: Spinner spinner = (Spinner) findViewById(R. id. spinner); ArrayAdapter<String> adapter = new ArrayAdapter<>(context, R.


2 Answers

you can try this

ArrayAdapter<String> SpinerAdapter;
         String[] arrayItems = {"Strawberry","Chocolate","Vanilla"};
         final int[] actualValues={10,20,30}; 

        SpinerAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item, arrayItems);
        spinner.setAdapter(SpinerAdapter);

        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                int thePrice=actualValues[ arg2];

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });
like image 62
Mohsin Naeem Avatar answered Sep 21 '22 08:09

Mohsin Naeem


i think this post will help you Android: How to bind spinner to custom object list?

this question author has the same requirement as you

like image 20
sunil Avatar answered Sep 23 '22 08:09

sunil