80,472
社区成员




spnSYDK = (Spinner)findViewById(R.id.spn_test1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, strChannelNumber);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnSYDK.setAdapter(adapter);
spnSYDK.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
/* 将所选mySpinner 的值带入myTextView 中*/
Log.d("test","onItemSelected arg2 = " + arg2);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
Log.d("test","onNothingSelected ");
}
});
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
android:layout_width="fill_parent" android:orientation="vertical" android:weightSum="1">
<TextView android:textAppearance="?android:attr/textAppearanceLarge" android:text="Sample Text" android:id="@+id/textView1" android:layout_gravity="top" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center_horizontal"></TextView>
<Spinner android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/spn_test1"/>
<ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView>
</LinearLayout>