我使用下面的代码创建一个简单的Spinner(只允许单个选择)
但现在我想知道如何使用微调器进行多重选择,我知道我可以使用Dialog实现这一点,但我必须使用Spinner ..
public class MainActivity extends Activity {
Spinner spnr;
String[] celebrities = {
"Chris Hemsworth",
"Jennifer Lawrence",
"Jessica Alba",
"Brad Pitt",
"Tom Cruise",
"Johnny Depp",
"Megan Fox",
"Paul Walker",
"Vin Diesel"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spnr = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, celebrities);
spnr.setAdapter(adapter);
spnr.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
int position = spnr.getSelectedItemPosition();
Toast.makeText(getApplicationContext(),"You have selected "+celebrities[+position],Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
);
}
}