如何获得多个微调在android系统,其中一个微调的价值取决于其他微调的价值? [英] How to get multiple spinner in android where value of one spinner depends on value of other spinner?

查看:153
本文介绍了如何获得多个微调在android系统,其中一个微调的价值取决于其他微调的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在安卓例如1微调为国家的动态微调,并根据国家中选择的价值,我想另一个微调的状态。

I want to have dynamic spinner in android e.g one spinner for country and depending upon the value selected in Country, i want to get another spinner for states.

推荐答案

我相信你可以用OnItemSelectedListener解决这个问题。

I believe you can solve this with the OnItemSelectedListener.

public void onCreate() {
     ....
    Country[] mCountries = ... ;
    final Spinner spinner1 = ...;
    final Spinner spinner2 = ...;

    spinner1.setAdapter(new ArrayAdapter(mCountries);
    spinner1.setOnItemSelectedListener( new OnItemSelectedListener() {

    void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        Country country = (Country) parent.getAdapter().getItem(position);
        spinner2.setAdapter(new ArrayAdapter(country.getStates());
     }
     void onNothingSelected(AdapterView<?> parent) {
        spinner2.setAdapter(null);
     }
    });
 ....
}

这篇关于如何获得多个微调在android系统,其中一个微调的价值取决于其他微调的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆