Android 2.3.3 | How to make Spinner simply display information and prevent users from viewing options

Do I have a Spinner that I want to be editable or interact with some users and just use to view information for other users? Is there a way to make Spinner to display information that I would have previously selected in the background.

+4
source share
1 answer

In xml, you can simply add this line to the Spinner element:

android:clickable="false" 

Then you can display the information you need, but it is not available. If you need to do this programmatically, you can simply use this line of code:

 mySpinner.setClickable(false); 

And just in case, you need to know how to display certain information:

 Spinner mySpinner = (Spinner) spinnerlayout.findViewById(R.id.myspinner); //Here you set the String array to use ArrayAdapter<CharSequence> adapter = ArrayAdapter .createFromResource(this, R.array.STRING_ARRAY_USED, R.layout.spinner); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mySpinner.setClickable(false); mySpinner.setAdapter(adapter); mySpinner.setSelection(HERE YOU SET THE INDEX OF THE ARRAY ITEM TO SHOW); mySpinner .setOnItemSelectedListener(new MyOnItemSelectedListener()); 
+6
source

Source: https://habr.com/ru/post/1393540/


All Articles