0

I have 14 items in my spinner. But i want to hide some items for different conditions.

For eg

I want to hide last 2 items for condition 1,last 4 for condition 2 and so on..

Is it possible to hide/destroy items of spinner like hiding whole spinner using setVisibility method?

1 Answers1

1

You can try this custom adapter to hide items from spinner based on position of item in spinner.

public class CustomAdapter extends ArrayAdapter<String> {

     private int hidingItemIndex;

     public CustomAdapter(Context context, int textViewResourceId, String[] objects, int hidingItemIndex) {
         super(context, textViewResourceId, objects);
         this.hidingItemIndex = hidingItemIndex;
     }

     @Override
     public View getDropDownView(int position, View convertView, ViewGroup parent) {
         View v = null;
         if (position == hidingItemIndex) {
             TextView tv = new TextView(getContext());
             tv.setVisibility(View.GONE);
             v = tv;
         } else {
             v = super.getDropDownView(position, null, parent);
         }
         return v;
     }
 }

check this link for reference How to hide one item in an Android Spinner

the other way would be removing item from array list and set to spinner.

Community
  • 1
  • 1
santosh kumar
  • 2,952
  • 1
  • 15
  • 27