title: how to get position or index of element in spinner
body: <p>I have a spinner in my code and I want to get position of element in the array when selected. Here is my code which is running perfectly. In selection I am storing the string value of  element but I also want the position count of element</p>
  
  <pre><code>public class MainActivity extends Activity implements OnItemSelectedListener {
      final Context context = this;
      private Button button;
      private String selection;
      private String[] states  = new String[]{
              "Gujrat","Jammu and Kashmir","Kerala","Karnataka","Lakshadweep","Maharashtra","Manipur","Mizoram",
              "Nagaland","New Delhi","Rajasthan","Tami Nadu","West Bengal"
      };
      ArrayList&lt;String&gt; categoryList = new ArrayList&lt;String&gt;();
      private static final String TAG = "MyActivity";
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          int currentMonth = Calendar.getInstance().get(Calendar.MONTH)+1;
  
          //make it fullscreen
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
          //fix portrait orientation
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  
          setContentView(R.layout.activity_main);
          ImageView img = (ImageView)findViewById(R.id.imageView1);
          img.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
  
                  // custom dialog
                  final Dialog dialog = new Dialog(MainActivity.this);
                  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  dialog.setContentView(R.layout.menu);
                  Button dialogButton = (Button) dialog.findViewById(R.id.btncross);
                  // if button is clicked, close the custom dialog
                  dialogButton.setOnClickListener(new OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          dialog.dismiss();
                      }
                  });
  
                  dialog.show();
                  Spinner spin = (Spinner)dialog.findViewById(R.id.spinState);
                  ArrayAdapter&lt;String&gt; adapter_state = new ArrayAdapter&lt;String&gt;(MainActivity.this,  android.R.layout.simple_spinner_item, states);
                  adapter_state.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                  spin.setAdapter(adapter_state);
  
                  spin.setOnItemSelectedListener(MainActivity.this);
              }
          });
  
  
  
      }
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
                                 long arg3) {
          // TODO Auto-generated method stub
          TextView tv = (TextView)arg1;
          selection = tv.getText().toString();
          Log.v(TAG, "index=" + selection);
  
      }
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>