0

In my activity_main.xml file i have one spinner and one button.

Where spinner values are coming from mysql database.

I just only want the position of selected value of spinner after clicking on Button.

MainActivity.java file -

    button.setOnClickListener(this);

     @Override
     public void onClick(View v) {

    if(v==button)
    {

        String Pos= spinner.getSelectedItem().toString();
        Toast.makeText(getApplicationContext(),Pos,Toast.LENGTH_SHORT).show();

    }
}

But here i only get the selected Item not position.

Maneesh Sharma
  • 63
  • 1
  • 12
  • Sorry Mike but i want position after clicking the button . – Maneesh Sharma Apr 22 '17 at 04:41
  • What's the problem, exactly? Change the first line in your `if` block to `int pos = spinner.getSelectedItemPosition();`. – Mike M. Apr 22 '17 at 04:49
  • This thing i have used already but it terminates the app – Maneesh Sharma Apr 22 '17 at 05:03
  • That's something you need to mention in the question, so we don't have people wasting their time posting solutions that you've already tried. Furthermore, when your app crashes unexpectedly, you need to investigate why that happens, and if you still need help, you need to provide as many details as you can, including [the stack trace](http://stackoverflow.com/questions/23353173). Anyway, you can't pass an arbitrary `int` to `Toast.makeText()` for the text. That parameter is for a `String` resource ID. Convert the `int` to a `String` first: `String.valueOf(pos)`. – Mike M. Apr 22 '17 at 05:10
  • 1
    MIke Thanks for your guidence , and thanks for you code suggestion. it works now... – Maneesh Sharma Apr 22 '17 at 05:58

0 Answers0