Reputation: 556
I am using a spinner as navigation for my app, and need to know how to reset it when the user uses the back button. Currently when a user selects a page and goes back, the spinner is on the previously selected bar, and not the current page. Here is my current code.
public void spinnerNavigation(){
Spinner mySpinner = (Spinner) findViewById( R.id.spinner1);
mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View v, int i, long lng) {
if (i == 0) {
// current page
} else if (i == 1) { // Second item
Intent myIntent = new Intent(getBaseContext(), LearnActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
} else if (i == 2) { // Third item
Intent myIntent = new Intent(getBaseContext(), QuizActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
} else if (i == 3) { // Fourth item
Intent myIntent = new Intent(getBaseContext(), ForumActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// Do nothing
}
});
}
Upvotes: 8
Views: 10179
Reputation: 22028
If you want to reset it to the first item:
mySpinner.setSelection(0);
_____________________
Upvotes: 15