Using a spinner


Last Updated:

  1. Mats

    Mats New Member This Topic's Starter

    Joined:
    Nov 1, 2009
    Messages:
    1
    Likes Received:
    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 (Text):
    1. TextView weeknr = (TextView) findViewById(R.id.week);
    2. weeknr.setText("the selected one");
    The spinner java code
    Code (Text):
    1.         Spinner kiesklas = (Spinner) findViewById(R.id.lijstklas);
    2.         ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.klassen, android.R.layout.simple_spinner_item);
    3.         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    4.         kiesklas.setAdapter(adapter);
    The XML file called array.xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <resources>
    3.     <string-array name="klassen">
    4.         <item>-</item>
    5.         <item>AP_KEU1-1</item>
    6.         <item>AP_KEU1-2</item>
    7.         <item>AP_KEU1-3</item>
    8.         <item>AP_KEU1-4</item>
    9.         <item>AP_KEU1-5</item>
    10.         .....
    11.     </string-array>
    12. </resources>
     

    Advertisement
  2. gauntface

    gauntface Member

    Joined:
    Nov 2, 2009
    Messages:
    11
    Likes Received:
    0
    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
     

Share This Page

Loading...