【问题标题】:populate Multiple(4) spinner in activity from webservice based on each spinner selection根据每个微调器选择从 web 服务中填充活动中的 Multiple(4) 微调器
【发布时间】:2017-04-24 14:37:38
【问题描述】:

填充微调器的数据完全来自 webservice(xml)。 应用不维护任何用于填充微调器数据的本地数据...

我需要通过以动态方式使用 web 服务,根据微调器值的选择逐个获取每个微调器值。 通过网络服务填充一个国家。 基于国家,通过网络服务填充城市。 基于国家和城市,通过网络服务填充密码。 根据国家、城市和密码,通过网络服务填充银行名称并继续。

我怎样才能顺利实现这一点以获得更好的用户界面.....

【问题讨论】:

  • 为每个微调器设置点击监听器并调用适当的网络服务并将数据放入下一个微调器
  • @Divyesh 在 UI 中运行顺畅吗?
  • 是的,使用正确的方式设置监听器

标签: android xml web-services android-spinner dynamic-data


【解决方案1】:
    If you are recieving array value of all spiiners in api then you also need the values which is select by default in that api.


    i.e
    {
    data:{
    city:[
    "X",
    "Y",
    "Z"
    ]
    },
    dataSelected:{
    city:"X"
    }
    }

//after parsing

spinnerCity.setadaper(new ArrayAdapter<String>(getActivity(), R.layout.layout_simple_spinner_dropdown_table, arrCity));

 String selectedStr = "X";
                        String cap = selectedStr.substring(0, 1).toUpperCase() + selectedStr.substring(1);
                        int spinnerPosition = arrCity.indexOf(cap);
                        spinnerCity.setSelection(spinnerPosition);

【讨论】:

  • 对于解析,AsynTask 效果好吗?因为它需要在每次选择之后通过解析来自同一活动中的 web 服务的值来加载数据。
  • 你应该使用Async Task解析一次并进一步存储响应并通过存储的响应进行操作。
  • 我没有立刻打这个电话。实际上我需要在选择微调器值后调用 web 服务(我需要将选定的微调器值作为参数发送到下一个 web 服务以从服务器获取值。)。
  • spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; parentView, View selectedItemView, int position, long id) { //call service here with params and get data for next spinner and fill that new abc().execute(spinner.getSelectedItem(position).toString()); } @Override public void onNothingSelected(AdapterView&lt;?&gt; parentView) { } });
猜你喜欢
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-16
  • 1970-01-01
  • 2013-04-09
  • 1970-01-01
相关资源
最近更新 更多