Kitinz
Kitinz

Reputation: 1542

Catch a Spinner selection with a Button?

As the title says, i have a Spinner with just a couple of options and a button. I didnt declared any Listener for the spinner, instead of that, what i want is use the button and perform different actions depending on the spinner selected option.

So, i declared a handler in the button option "android:onClick", but once there, i dont know how to access the option selected in the Spinner.

Can anybody help me?

Thank you!

Upvotes: 0

Views: 1173

Answers (2)

peter
peter

Reputation: 36

spinner.setAdapter(this.adapter); 
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(AdapterView<?> adapterView,View view,int i,long l){
        //TODO handle the event
    }
});

use the above code to catch the selected spinner optin with a button

Upvotes: 0

fhucho
fhucho

Reputation: 34560

Call getSelectedItemPosition() on the Spinner. Also you may look at Spinner's reference: http://developer.android.com/reference/android/widget/Spinner.html. Click on "Exapand all" in the top right corner and search for "getselect" for other ways to get selected item info.

Upvotes: 1

Related Questions