【问题标题】:Android: Spinner not showing the selected valueAndroid:微调器未显示所选值
【发布时间】:2016-02-05 05:25:38
【问题描述】:

我有一个微调器和下拉列表,微调器的值来自 JSON 解析。我的问题是值设置到微调器中,但是当我从下拉列表中选择一个值时,它没有显示在微调器中选中后,始终为空白。

我将微调器初始化为

final Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
final List<String> money = new ArrayList<String>();

Assync 任务 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); ,当时所有值都显示在微调器中。

谁能告诉我哪里错了,为什么它没有在微调器中显示选定的值

【问题讨论】:

  • 您是否使用任何类型的background 来代替Spinner
  • 能否请您添加您的微调器 xml 代码

标签: android spinner android-spinner


【解决方案1】:

这将对您有所帮助:-

   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) {
        }
    });

【讨论】:

    猜你喜欢
    • 2013-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多