xain
xain

Reputation: 13849

Disabling Spinner in android

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

Upvotes: 78

Views: 92777

Answers (5)

Todd Campbell
Todd Campbell

Reputation: 9

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

Will not work

Actual code that will work ...

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

Upvotes: -1

himb2001
himb2001

Reputation: 1361

Disable or enable it before setting the adapter.

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

Upvotes: 118

DN2048
DN2048

Reputation: 3804

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);

Upvotes: 31

AlbeyAmakiir
AlbeyAmakiir

Reputation: 2247

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

Upvotes: 12

Zephyr
Zephyr

Reputation: 6361

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

Upvotes: 20

Related Questions