Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't android:clickable="false" work for Spinner?

The following spinner is still clickable to show the list:

<Spinner
    android:id="@+id/spinnerFoo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginLeft="15dp"
    android:gravity="center"
    android:clickable="false"/>

Could anyone shed some light on this? I know from my reading that one can disable a spinner by doing it in Java code (spinnerFoo.setEnabled(false). My question is about doing it in XML.

[EDIT] The following is all the Java code using the spinner:

ArrayAdapter<Integer> adapterFoo = new ArrayAdapter<Integer>(this, R.layout.spinner_item, aiFoo);
spinnerFoo = (Spinner) findViewById(R.id.spinnerFoo );
spinnerFoo .setAdapter(adapterFoo );
spinnerFoo .setSelection(1);
like image 839
Hong Avatar asked Dec 12 '25 13:12

Hong


1 Answers

Clickable is not going to stop the spinner from opening because it does not depend on click event.You have to use android:enabled="false"

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

like image 98
Arpan Sharma Avatar answered Dec 15 '25 05:12

Arpan Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!