Richard Dyer
Richard Dyer

Reputation: 121

Android Spinner How to not show specific selections

I have a spinner in a toolbar, I also have replaced the toolbar with an icon and when the user selects the first option and the last option in the spinner I do not want it to show, or in other words do not want to replace the Spinner with text but the rest for the rest between the first and last option. I want them to show. How can I do this?

 public void onItemSelected(AdapterView<?> adapterView,
                                   View view, int i, long l) {
            int total = adapterView.getCount();
            if(i == 0){

            }
            else if(i == total -1){

            }

Upvotes: 0

Views: 59

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

// declare it inside class
private int prev_pos=0; // initially it zero, you can set your desire position 

if(i =! 0 && i!= adapterView.getCount()-1 )
{
  // do what you want
  prev_pos=i; // store the previous position if it's not last or first
}
else{
 // display previous position 
 yourSpinnerObject.setSelection(prev_pos);
}

Upvotes: 1

Related Questions