• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Using a spinner

Mats

Lurker
Nov 1, 2009
1
0
Hi everyone,

I'm just started with android developing but I'm facing a problem.

I made a good working spinner but how do i use it? I want that when i select for example "AP_KEU1-1" that in a text box "AP_KEU1-1" appears.

The writing down of the text is easy i do that with this code but how do i get the variable that is selected

Code:
TextView weeknr = (TextView) findViewById(R.id.week);
weeknr.setText("the selected one");
The spinner java code
Code:
        Spinner kiesklas = (Spinner) findViewById(R.id.lijstklas);
        ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.klassen, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        kiesklas.setAdapter(adapter);
The XML file called array.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="klassen">
        <item>-</item>
        <item>AP_KEU1-1</item>
        <item>AP_KEU1-2</item>
        <item>AP_KEU1-3</item>
        <item>AP_KEU1-4</item>
        <item>AP_KEU1-5</item>
        .....
    </string-array>
</resources>
 
Mats,

I think the Spinner handles which element is selected and displaying it in the spinner View / Button (However you think of it).

I think you can then query the spinner for which element is currently selected.

I ended up implementing my own Spinner to get the look and actions I wanted which isn't too hard to do, just a button and a Dialog which you then use a Dialog result on when it's closed.

Either I'm fairly sure the documentation on Spinners are pretty good.

Matt
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones