Android drop-down menu, such as <select> in HTML, the key is to call the Setdropdownviewresource method, in XML to define the appearance of the Drop-down menu to display
1.1.activity_main.xml
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns: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" tools:context= "com.rj141.sb.kongjian.MainActivity" > <linea Rlayout android:orientation= "Horizontal" android:layout_width= match_parent "android:layout_height=" Wrap_co
Ntent "> <textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content " Android:textsize= "18DP" android:text= "Please choose your favorite fruit:"/> <spinner android:layout_width= "Match_par Ent "android:layout_height=" wrap_content "android:id=" @+id/spinner "/> </LinearLayout> &l T
TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:textsize= "18DP" Android:id= "@+id/tv"/>
</LinearLayout>
Spinner is the component of the Drop-down list
1.2.mainactivity.class
public class Mainactivity extends Appcompatactivity {private Spinner s;
String[] data=new string[]{"Apple", "Sydney", "watermelon", "Grape", "orange", "Strawberry"};
Private TextView TV;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
tv= (TextView) This.findviewbyid (r.id.tv);
S= (Spinner) This.findviewbyid (R.id.spinner); S.setadapter (New arrayadapter<string> (this,android).
R.layout.simple_list_item_1,data)); S.setonitemselectedlistener (New Adapterview.onitemselectedlistener () {@Override public void onitemselected (
Adapterview<?> Parent, view view, int position, long id) {String str=data[position];
Tv.settext ("Favorite fruit is:" +str);
@Override public void onnothingselected (adapterview<?> parent) {}}); } s.setadapter (New Arrayadapter<string> (this,android). R.layout.simple_list_item_1,data));Ndroid. R.layout.simple_list_item_1 refers to Android's own Drop-down list format, where data is the source; S.setonitemselectedlistener (new Adapterview.onitemselectedlistener ()) {..} ; Is the monitor of the dropdown list
Effect Chart:
The above is the entire content of this article, I hope to learn how to master the Android implementation of the Pull-down menu spinner components help.