Android Spinter Markup

I set the dynamic value in the counter. I am using the following code for it.

spinner_generalbooks.setAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, new String[]{"Author","ISBN","Keyword","Title"})); 

It works fine, but I have a problem with the view of the counter. If we select simple_spinner_item , this is normal in the normal state, but when we want to change it, the lines are very narrow, not CheckedTextView , whereas in the usual spinner parameters - CheckedTextView . If you select simple_spinner_dropdown_item , the parameters have a CheckedTextView , but in the normal state they look different than in Fig.

(The first one is used by default, and the second one uses simple_spinner_dropdown_item ).

First one is default spinner and second one is using <code> simple_spinner_dropdown_item </code>

I want to show the spinner in the same way as by default. How to do it?

+4
source share
2 answers

Android will accept the layout specified in the adapter and will use it for the control and elements unless you specify a view resource separately. By doing this, you can set the simple_item layout in the ArrayAdapter constructor, and then set the dropdown_item layout separately in the setDropDownViewResource () call.

 ArrayAdapter newAdapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, new String[]{"Author","ISBN","Keyword","Title"}); newAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_generalbooks.setAdapter(newAdapter); 
+5
source

If you want to customize the visualization of your Spinner, it will be easier for you to create your own component. Spinner is just a layout containing text, an image and a list in a popup window. Create your own layout for your element and use the new BaseAdapter object to bind your data.

http://thinkandroid.wordpress.com/2010/01/13/custom-baseadapters/

hope i can help

+1
source

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


All Articles