I am new to android programming. I imagine that my problem is that the
spinner is defined but is not connected to the array that I have defined in
res>values>strings.xml

I have code related to the spinner in 3 different places, is that correct? I
am open to improving my coding style.

In main.xml I have this code:

<http://www.anddev.org/#><Spinner
   android:id="@+id/Spinner01"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
   </Spinner>

In SpinnerThingy.java I have this code:

package com.mymortgagegenius.mortgagecalc;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;


public class SpinnerThingy extends Activity {
   void showToast(CharSequence msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
       ArrayAdapter<String> adapter = new ArrayAdapter<String>(
               this, android.R.layout.simple_spinner_item,
R.array.compoundingSpinner);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
       spinner.setAdapter(adapter);

       spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
   }
}

In MyOnItemSelectedListener.java I have:

<http://www.anddev.org/#>package com.mymortgagegenius.mortgagecalc;

import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class MyOnItemSelectedListener implements OnItemSelectedListener {

                public void onItemSelected(
                       AdapterView<?> parent, View view, int pos, long id) {
                    Toast.makeText(parent.getContext(), "The planet is " +
                            parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_LONG).show();
                }

                public void onNothingSelected(AdapterView<?> parent) {
                   // Do nothing.
                }
}

This is the effect of clicking on the Spinner:
[image: Image]

Connie

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to