Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable an item in a Spinner

Tags:

android

Is it possible to display particular entries in a Spinner list as disabled?

I.e., I want to always display a spinner with four entries (North, South, East, and West, say), but I want to be able to disable any one of these so that is appears greyed out and not selectable.

Is this possible, or will I have to recreate the list each time, leaving out the invalid entries?

like image 679
FrinkTheBrave Avatar asked Aug 26 '10 11:08

FrinkTheBrave


People also ask

How do you make a spinner Not selectable?

You will have to set the prompt attribute of spinner. spinner. setPrompt("Title");

How do you set a spinner to a specific position?

Code is as follows: Spinner spinner = new Spinner(this); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.

What is spinner method?

Spin bowling is a bowling technique in cricket, in which the ball is delivered slowly but with the potential to deviate sharply after bouncing. The bowler is referred to as a spinner.


1 Answers

   // Create spinner month, and disable month < today     List<CharSequence> listMonth = new ArrayList<CharSequence>();     for (int m = 0; m < 12; m++) {         if (m < 9) {             listMonth.add("0" + (m + 1));         } else {             listMonth.add("" + (m + 1));         }     }         // Create spinner item     adapterMonth = new ArrayAdapter<CharSequence>(this,             R.layout.layout_spinner_item, listMonth) {          // Disable click item < month current         @Override         public boolean isEnabled(int position) {             // TODO Auto-generated method stub             if (year <= max_year && position < max_month - 1) {                 return false;             }             return true;         }         // Change color item         @Override         public View getDropDownView(int position, View convertView,                 ViewGroup parent) {             // TODO Auto-generated method stub             View mView = super.getDropDownView(position, convertView, parent);             TextView mTextView = (TextView) mView;             if (year <= max_year && position < max_month - 1) {                 mTextView.setTextColor(Color.GRAY);             } else {                 mTextView.setTextColor(Color.BLACK);             }             return mView;         }     };      adapterMonth             .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     spn2.setAdapter(adapterMonth); 
like image 125
Luan Dang Avatar answered Sep 24 '22 19:09

Luan Dang