What's the correct way to implement key-value pair in Spinner in android
<p>Is this the correct way to implement key-value pair for a Spinner in Android?</p>

<pre><code>package com.mypackage

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
import android.widget.AdapterView;
import android.widget.TextView;

public class SpinnerAndAdapter extends Activity
{
    TextView    valueTextView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        valueTextView = (TextView)findViewById( R.id.selected );
        Spinner s = (Spinner)findViewById(R.id.spinner);
        final MyData items[] = new MyData[3];
        items[0] = new MyData( "key1","value1" );
        items[1] = new MyData( "key2","value2" );
        items[2] = new MyData( "key3","value3" );
        ArrayAdapter&lt;MyData&gt; adapter = 
            new ArrayAdapter&lt;MyData&gt;( 
                this,
                android.R.layout.simple_spinner_item,
                items );
        adapter.setDropDownViewResource(
            android.R.layout.simple_spinner_dropdown_item);
        s.setAdapter(adapter);
        s.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(
                        AdapterView&lt;?&gt; parent, 
                        View view, 
                        int position, 
                        long id) {
                    MyData d = items[position];
                    valueTextView.setText( d.getValue() );
                }

                public void onNothingSelected(AdapterView&lt;?&gt; parent) {
                }
            }
        );
    }

    class MyData {
        public MyData( String spinnerText, String value ) {
            this.spinnerText = spinnerText;
            this.value = value;
        }

        public String getSpinnerText() {
            return spinnerText;
        }

        public String getValue() {
            return value;
        }

        public String toString() {
            return spinnerText;
        }

        String spinnerText;
        String value;
    }
}
</code></pre>
