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?
You will have to set the prompt attribute of spinner. spinner. setPrompt("Title");
Code is as follows: Spinner spinner = new Spinner(this); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.
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.
// 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With