依赖android系统中的数据微调 [英] spinner data dependent in android

查看:126
本文介绍了依赖android系统中的数据微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题了

对此微调的布局和想要得到的依赖2微调
结构

Have 2 spinner on layout and wanna get dependence of this spinner Structure

String[] main={"Moscov","LosAngeles","Pekin"};
String[] one={"1","2","3","4"};
String[] two={"2","2","5","8"};
String[] tree={"5","7","3","2"};

创建用于主阵列第一微调第一适配器。
而对于依赖项目选择必须依赖与阵列混凝土适配器的选择
如果项目1然后用数组一个适配器,如果第2项则阵列中有两个

Create first adapter for first spinner with main array. And dependently for item choice must crete adapter with array which depend of choice If item 1 then adapter with array one, if item 2 then array two

推荐答案

您将创建微调键,只需设置适配器第二微调根据使用 onItemSelected 上的第一个微调<选择/ code>。类似

You will create your spinner and just set the Adapter for the second spinner according to the selection using onItemSelected on the first Spinner. Something like

@Override
public void onItemSelected(AdapterView<?> spinner, View view, int position,long arg3)
{
        TextView tv = (TextView)view;  // convert the view to TextView
        String selected = tv.getText().toString();
        if (selected.equals("Moscov"))
        {
            // set the Adapter here with the first set of values
        }
        else if(selected.equals("LosAngeles"))
        {
            // set the Adapter here with the second set of values
        }
        else
        {
            // set the Adapter here with the third set of values
        }
}

您也可以使用位置如果你把你的字符串数组到<$这可能是更具可扩展性C $ C>的ArrayList

You also could use the position which may be more scalable if you put your String Arrays into an ArrayList.

这篇关于依赖android系统中的数据微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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