In Android, the spinner is the drop-down box. When you click it, the selection list is displayed, from which you can select data. The data in the spinner must come from the adapter. Therefore, when adding data to it, you must first define the template, that is, the XML file in layout.
<? XML version = "1.0" encoding = "UTF-8"?>
<Textview
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Id = "@ + ID/tvcateitem"
Android: textsize = "14px"
Android: textcolor = "@ color/Black"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
</Textview>
Here we define only the display, using the textview control.
Then in the Code:
String [] Cates = new string [] {"Unclassified", "Learning"}; arrayadapter adapter = new arrayadapter (getapplicationcontext (), R. layout. spinner_cate_item, Cates); spcate. setadapter (adapter );
Run: