Disabling Spinner in android

雨燕双飞 提交于 2019-12-03 08:04:18

问题


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


回答1:


Disable or enable it before setting the adapter.

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



回答2:


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



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/5986130/disabling-spinner-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!