我有一个Spinner的故事,我需要从资源的数组中恢复值到Spinner类型的字符串,我正在尝试将值记录为String并且不可能,请帮助
Greetens
大卫
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.spinner, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String item = parent.getItemAtPosition(position).toString();
Log.v("SPINNER", item);
}
public void onNothingSelected(AdapterView<?> parent) {
String str = "";
}
});
答案 0 :(得分:0)
您是否尝试过直接在onItemSelected中查询适配器,例如
String item = adapter(position).toString();