Disabling Spinner in android

AndroidSpinner

Android Problem Overview


I'm having problems when using android:enabled="false", it's not disabling the component in the case it's a spinner. Don't know if it's relevant, but it belongs to a layout that's part of a viewflipper.

Any hints or workarounds ?

Thanks

Android Solutions


Solution 1 - Android

Disable or enable it before setting the adapter.

yourSpinner.setEnabled(false);   
yourSpinner.setClickable(false);  
yourSpinner.setAdapter(typeAdapter);

Solution 2 - Android

It's not possible to enable/disable a Spinner in XML (yet). To do so you have to do it in code.

Here's an example:

Spinner spinner = (Spinner) findViewById(R.id.mySpinner);
spinner.setEnabled(false);

Solution 3 - Android

you can set android:clickable="false" in the xml to disable the spinner for click event.

Solution 4 - Android

You can set this in the Java code itself, instead of in the XML, because the Spinner should implement setEnabled(boolean) from View.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionxainView Question on Stackoverflow
Solution 1 - Androidhimb2001View Answer on Stackoverflow
Solution 2 - AndroidThe BergaView Answer on Stackoverflow
Solution 3 - AndroidZephyrView Answer on Stackoverflow
Solution 4 - AndroidAlbeyAmakiirView Answer on Stackoverflow