Reputation: 115
I have a Spinner.onItemSelected()
method and I want to be able to have an event happen once a Button
is clicked after selecting the Spinner
item.
For example if you select Beginner for your Spinner and click Java for another spinner. Under that I have a button that says Start. How do I have a Button.onClick
event correspond with the selected spinner options?
I did something like this but what I assigned as the setOnClickListener()
value is not being read by the View.OnClickListener
.
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
selected = (Integer) arg0.getItemAtPosition(0);
position = spinner.getSelectedItemPosition();
start = (Button)findViewById(R.id.start);
start.setOnClickListener(phaseHandler);
View.OnClickListener phaseHandler = new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
};
}
The phaseHandler
I declared is not being read by start.setOnClickListener(phaseHandler)
so this results in my View.OnCLickListenr
invocation not working because phaseHandler
is not being set to the Button
start. In Eclipse my phaseHandler
has the red underlining curly for an error where it says start.setOnClickListener(phaseHandler);
Any Ideas?
Upvotes: 0
Views: 1209
Reputation: 3992
move start.setOnClickListener(phaseHandler); down this may help you
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
selected = (Integer) arg0.getItemAtPosition(0);
position = spinner.getSelectedItemPosition();
start = (Button)findViewById(R.id.start);
View.OnClickListener phaseHandler = new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
};
start.setOnClickListener(phaseHandler);
}
Upvotes: 2