下面是关于Spinner的点击事件(效果图如上图):
- mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- String str=parent.getItemAtPosition(position).toString(); Toast.makeText(SpinnerActivity.this, "你点击的是:"+str, 2000).show();
- } @Override
- public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub
- } });
(二)使用自定义的Adapter(重点)
①:定义每一个Item的布局文件
- <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
- android:layout_width="match_parent" android:layout_height="match_parent"
- android:orientation="horizontal" > <TextView
- android:id="@+id/textView1" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_launcher"
- android:paddingRight="8dip" android:paddingTop="8dip"
- android:text="TextView" android:textSize="25sp" />
- <TextView android:id="@+id/textView2"
- android:layout_width="wrap_content" android:layout_height="wrap_content"










