问题描述
我有一个微调器和下拉列表,该微调器的值是从JSON解析中获取的.我的问题是该值设置在微调器中,但是当我从下拉列表中选择一个值时,它没有显示在微调器中选中后,它始终为空白.
我将微调器初始化为
final Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
final List<String> money = new ArrayList<String>();
异步任务Api解析onSuccess
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject c = jsonArray.getJSONObject(i);
String amount = c.getString("amount");
money.add(amount+" "+euro);
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, money);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
我注意到,在解析之前,是否在微调器中设置一个值,例如 money.add("0" +" + euro); ,当时所有值都显示在微调器中./p>
任何人都可以告诉我哪里出了问题吗,为什么它没有在微调器中显示选定的值
这将帮助您:-
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long id) {
// selectedItem = money[position];
//OR
spinner.setSelection(arrayAdapter.getPosition(pos));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
I have a spinner and drop down list, the value for the spinner is getting from JSON parsing.My problem is the value is setting into the spinner but when i select a value form the drop down it is not showing in the spinner as selected, it is always blank.
I initialize the spinner as
final Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
final List<String> money = new ArrayList<String>();
Assync task Api parsing onSuccess
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject c = jsonArray.getJSONObject(i);
String amount = c.getString("amount");
money.add(amount+" "+euro);
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, money);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
I notice that before parsing if set a value in spinner like money.add("0"+" "+euro); , at the time all the value is showing in the spinner.
Can anyone please tell me where am wrong, why it is not showing the selected value in the spinner
This will helps you :-
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long id) {
// selectedItem = money[position];
//OR
spinner.setSelection(arrayAdapter.getPosition(pos));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
这篇关于Android:微调框未显示所选值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!