这样做,
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.Toast;
import com.meta.R;
public class SpinnerActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner sp1, sp2, sp3, sp4, sp5;
sp1 = (Spinner) findViewById(R.id.spinner1);
sp2 = (Spinner) findViewById(R.id.spinner2);
sp3 = (Spinner) findViewById(R.id.spinner3);
sp4 = (Spinner) findViewById(R.id.spinner4);
sp5 = (Spinner) findViewById(R.id.spinner5);
sp1.setOnItemSelectedListener(myListener);
sp2.setOnItemSelectedListener(myListener);
sp3.setOnItemSelectedListener(myListener);
sp4.setOnItemSelectedListener(myListener);
sp5.setOnItemSelectedListener(myListener);
}
OnItemSelectedListener myListener=new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
switch (arg2) {
case 1:
Toast.makeText(SpinnerActivity.this,"Spinner 1", Toast.LENGTH_LONG).show();
break;
case 2:
Toast.makeText(SpinnerActivity.this, "Spinner 2", Toast.LENGTH_LONG).show();
break;
case 3:
Toast.makeText(SpinnerActivity.this, "Spinner 2", Toast.LENGTH_LONG).show();
break;
case 4:
Toast.makeText(SpinnerActivity.this,"Spinner 2", Toast.LENGTH_LONG).show();
break;
case 5:
Toast.makeText(SpinnerActivity.this, "Spinner 2", Toast.LENGTH_LONG).show();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
};
}