1. Are you ready for the Galaxy S20? Here is everything we know so far!

Help with spinner

Discussion in 'Android Development' started by dmobb, Aug 8, 2012.

  1. dmobb

    dmobb Lurker
    Thread Starter

    I am trying to use a spinner in my app as a drop down menu.

    Here is the xml code:
    <Spinner
    android:id="@+id/fromSpinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:spinnerMode="dropdown"
    android:entries="@array/from_array" />

    Here is the Java code:

    Spinner fromSpinner = (Spinner) findViewById(R.id.fromSpinner);
    Spinner toSpinner = (Spinner) findViewById(R.id.toSpinner);
    ArrayAdapter<String> toAdapter = new ArrayAdapter<String>(this, R.id.toSpinner, R.array.to_array);
    toSpinner.setAdapter(toAdapter);
    ArrayAdapter<String> fromAdapter = new ArrayAdapter<String>(this, R.id.fromSpinner, R.array.from_array);
    fromSpinner.setAdapter(fromAdapter);
    String toCurrency = (String) toSpinner.getSelectedItem();
    String fromCurrency = (String) fromSpinner.getSelectedItem();

    I'm not sure what the adapters do but I think I need them. Anyway toCurrency and fromCurrency aren't getting the values they are supposed to get. Anyone know what I am doing wrong. I am a complete noob so it may be something really dumb.

    In case it helps the entire app source is at https://github.com/Dmobbjr/CurrencyCalculator
    This is the first app I am trying to make without a tutorial. I was able to get everything working except this.
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Help spinner
  1. LAYLA1337
    Replies:
    0
    Views:
    97
  2. Joseph Floyd Muckey
    Replies:
    5
    Views:
    215
  3. Sebastian huth
    Replies:
    0
    Views:
    214
  4. kylabeardad
    Replies:
    6
    Views:
    614
  5. FranzKafkaYs
    Replies:
    0
    Views:
    258
  6. EvasiveEmanual
    Replies:
    4
    Views:
    673
  7. ChristineDorotheaRickner
    Replies:
    26
    Views:
    724
  8. FingleFangle
    Replies:
    1
    Views:
    897
  9. John9870
    Replies:
    6
    Views:
    434
  10. Gihansurendra
    Replies:
    3
    Views:
    389

Share This Page

Loading...