布局:
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
使用:
private Spinner mSpinner;
private ArrayAdapter<String> adapter;
mSpinner = (Spinner) findViewById(R.id.spinner1);
//数据赋值
itemListManner = new ArrayList<String>();
for (int i = 0; i < 3; i++) {
itemListManner.add("审批方式 " + i);
}
//填充数据
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, itemListManner);
mSpinner.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String str=parent.getItemAtPosition(position).toString();
Toast.makeText(BacklogApproval.this, "你点击的是:"+str, 2000).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});