This example describes the spinner usage of the Android control. Share to everyone for your reference. Specifically as follows:
Use of the following emulated Drop-down lists
Layout file:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout android:id=
"@+id/linearlayout01"
android: Layout_width= "Fill_parent" android:layout_height= "fill_parent"
android:orientation= "vertical"
xmlns: Android= "Http://schemas.android.com/apk/res/android" >
<textview android:text= "@string/ys"
Android : id= "@+id/textview01"
android:layout_width= "fill_parent"
android:layout_height= "Wrap_content"
Android:textsize= "28dip"/>
<spinner android:id= "@+id/spinner01" android:layout_width= "Fill_"
Parent "
android:layout_height=" wrap_content "/>
</LinearLayout>
Spinneractivity class:
Package com.ljq.sp;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.AdapterView;
Import Android.widget.BaseAdapter;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;
Import Android.widget.Spinner;
Import Android.widget.TextView;
Import Android.widget.AdapterView.OnItemSelectedListener;
public class Spinneractivity extends activity {private Spinner SP = null;//dropdown list private TextView TV = null;
Array of all resource pictures private int[] Drawableids={r.drawable.football,r.drawable.basketball,r.drawable.volleyball};
Array of all strings private int[] MSGIDS={R.STRING.ZQ,R.STRING.LQ,R.STRING.PQ};
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
TV = (TextView) Findviewbyid (R.ID.TEXTVIEW01);
sp= (Spinner) This.findviewbyid (R.ID.SPINNER01);//Initialize Spinner Sp.setadapter (adapter); Sp.setonitemselectedlistEner (New Onitemselectedlistener () {public void onitemselected (adapterview<?> parent, view view, int positon, long
ID) {LinearLayout ll = (linearlayout) view;
View v=ll.getchildat (0);//Get First control ImageView log.i ("Ljq", V.getclass (). GetName ());
TextView TVN = (TextView) ll.getchildat (1);//Get second control TextView StringBuilder sb = new StringBuilder ();
Sb.append (Getresources (). GetText (R.string.ys)). Append (":"). Append (Tvn.gettext ());
Tv.settext (Sb.tostring ());
public void onnothingselected (adapterview<?> parent) {}});
Private Baseadapter adapter = new Baseadapter () {public int getcount () {return drawableids.length;
Public Object getitem (int position) {return drawableids[position];
public long getitemid (int position) {return position; Public View GetView (int position, View Convertview, ViewGroup parent) {LinearLayout LL = new LinearLayout (spinneract
Ivity.this);
Ll.setorientation (linearlayout.horizontal); ImageView IV = new ImagevIew (Spinneractivity.this);
Iv.setimageresource (Drawableids[position]);
Ll.addview (iv);
TextView tv=new TextView (spinneractivity.this);
Tv.settext (Msgids[position]);/set content tv.settextsize (24);
Tv.settextcolor (R.color.black);
Ll.addview (TV);
return ll;
}
};
}
Run results
I hope this article will help you with your Android order design.