Reputation: 1542
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
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
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