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?
You can hide spinner in the ProgressButton by setting the e-hide-spinner property to cssClass . Is this page helpful?
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<?>
Here is an workaround: Spinner spinner = (Spinner) findViewById(R. id. spinner); ArrayAdapter<String> adapter = new ArrayAdapter<>(context, R.
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
}
});
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With