[英]Spinner only saving first word to string
I am trying to get the spinner to display the item which i have selected. 我试图让微调器显示我选择的项目。 But it is only displaying the first word even if i choose the ones below. 但是,即使我选择下面的单词,它也只会显示第一个单词。 Here is the code i am using 这是我正在使用的代码
ArrayAdapter<String> aa1 = new ArrayAdapter<String>(
getApplicationContext(), R.layout.spinner_item, R.id.textView1, al);
spFacilityType.setAdapter(aa1);
spFacilityType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
int index = arg0.getSelectedItemPosition();
position = index;
}
});
final String Strspinner = spFacility.getItemAtPosition(position).toString();
使用onItemSelected而不是onNothingSelected。
do the code in onItemSelected().. 在onItemSelected()中执行代码。
String s= spFacilityType.getSelectedItem().toString();
now s will show the selected item 现在s将显示所选项目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.