Learn spinner Today
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" ><SpinnerAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:entries= "@array/books"android:prompt= "@string/tip" /> <SpinnerAndroid:id= "@+id/spinner"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:prompt= "@string/tip" /></LinearLayout>
<?XML version= "1.0" encoding= "Utf-8"?><Resources> <String-arrayname= "Books"> <Item>Java</Item> <Item>Android</Item> <Item>Web</Item> </String-array></Resources>
PackageCom.example.spinner;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.Spinner; Public classMainactivityextendsActivity {Spinner Spinner; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Spinner=(Spinner) Findviewbyid (R.id.spinner); String[] Arr={"Monkey King", "Pig", "Tang priest"}; Arrayadapter<String> adapter=NewArrayadapter<string> ( This, Android. R.layout.simple_list_item_multiple_choice, arr); Spinner.setadapter (adapter); }}
Android 16th Lesson--spinner