Needless to say, the drop-down list is often the spinner control.
Directly on the code:
PackagePeng.liu.testview;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.AdapterView;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.Spinner;ImportAndroid.widget.Toast; Public class mainactivity extends Activity { PrivateSpinner Spinner; string[] data =Newstring[]{"Android","Hello","World"};@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Spinner = (spinner) Findviewbyid (R.id.spinner); Spinner.setadapter (NewArrayadapter<string> ( ThisAndroid. R.layout.simple_list_item_1,data)); Spinner.setonitemselectedlistener (NewAdapterview.onitemselectedlistener () {@Override Public void onitemselected(adapterview<?> Adapterview, view view,intILongL) {toast.maketext (mainactivity). This, Data[i],toast.length_long). Show (); }@Override Public void onnothingselected(adapterview<?> Adapterview) { } }); }}
Layout code
<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:paddingleft="@dimen/activity_horizontal_margin"android:paddingright="@dimen/activity_horizontal_margin"android:paddingtop="@dimen/activity_vertical_margin"Android:paddingbottom="@dimen/activity_vertical_margin"tools:context=". Mainactivity "android:orientation="Vertical"> <spinner android:layout_width="Match_parent"android:layout_height="Wrap_content"Android:id="@+Id/spinner"/></linearlayout>
Android drop-down list control spinner-andoid learning Journey (11)