1

I want to make spinner item un-selectable or disabled How it is possible if I am using ArrayAdapter:

ArrayAdapter<String> adptr= new ArrayAdapter<String>(getActivity(),R.layout.custom_spinner_text,list);

list.add("select one");// i want to disable this .when i click on that it should not selected

list.add("Hello");

H.S
  • 159
  • 1
  • 5
  • 12

3 Answers3

2

You can override isEnabled(int position) of ArrayAdapter and return false to disable specific item. for example:

 @Override
    public boolean isEnabled(int position) {
        if (position == 4 )
           return false;           
        return true;
    }
Armin
  • 599
  • 2
  • 8
  • 19
0

this is example of the list but applied also for spinier

In order to disable list items on list creation you have to subclass from ArrayAdapter. You have to override methods as in link

Community
  • 1
  • 1
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
0

You probably have to remove that item from the Array("list" in your case) that you are using in the ArrayAdapter.

This can be done by filtering the array and removing the unwanted item from it.

like::

String list2[]=new String[];
for(int i=0;i<array.length;i++)
{
  if(!list[i].equals("Unwanted Item"))
   {
     list2[i]=list[i];
   }
}

Now you can use this list2 in the arrayadapter
I have use this logic in my application where i don't want some item to be seen by the certain type of User

Haresh Chaudhary
  • 4,390
  • 1
  • 34
  • 57