Spinner2的基础上选择的微调1的动态更新 [英] Dynamic update of Spinner2 based on choice in Spinner 1

查看:209
本文介绍了Spinner2的基础上选择的微调1的动态更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用此code(摘自<一个href="http://stackoverflow.com/questions/3984958/how-to-get-multiple-spinner-in-android-where-value-of-one-spinner-depends-on-valu/4491960#4491960">here)我得到以下错误:

  

构造ArrayAdapter(新   AdapterView.OnItemSelectedListener(){},   INT,字符串[])未定义

任何人都可以帮助纠正呢?谢谢

 私人无效setDynamicSpinnerBE(){
    beSpinner =(微调)findViewById(R.id.spBE);
    最终的String [] itemsSpinner2;
    lensSpinner.setOnItemSelectedListener(新OnItemSelectedListener(){

        公共无效onItemSelected(适配器视图&LT;&GT;母公司视图中查看,
                INT位置,长的id){
            整型长焦点=(整数)parent.getAdapter()的getItem(
                    位置);
            itemsSpinner2 = getBellowsExtension(长焦点,maxBellows,
                    precision);

            ArrayAdapter&LT; CharSequence的&GT; beAdapter =新的ArrayAdapter&LT; CharSequence的&GT;(
                    对此,android.R.layout.simple_spinner_item,
                    itemsSpinner2);
            beAdapter
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            beSpinner.setAdapter(beAdapter);

        }

        公共无效onNothingSelected(适配器视图&LT;&GT;母公司){
            beSpinner.setAdapter(空);
        }
    }

    );
    ...
}
 

解决方案

在构造新的 ArrayAdapter 以下行:

  ArrayAdapter&LT; CharSequence的&GT; beAdapter =新的ArrayAdapter&LT; CharSequence的&GT;(这一点,
 

指向 OnItemSelectedListener 类,你是在和不父视图当前的情况下,这是问题出现时,因为 ArrayAdapter 没有匹配的构造。你应该尝试使用 MyParentView.this (其中 MyParentView 是视图的名字你是),而不是传递相应的实例。

In using this code (adapted from here) I get the following error:

The constructor ArrayAdapter(new AdapterView.OnItemSelectedListener(){}, int, String[]) is undefined

Can anyone help correct this? Thanks

private void setDynamicSpinnerBE() {
    beSpinner = (Spinner) findViewById(R.id.spBE);
    final String[] itemsSpinner2;
    lensSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            Integer focalLength = (Integer) parent.getAdapter().getItem(
                    position);
            itemsSpinner2 = getBellowsExtension(focalLength, maxBellows,
                    precision);

            ArrayAdapter<CharSequence> beAdapter = new ArrayAdapter<CharSequence>(
                    this, android.R.layout.simple_spinner_item,
                    itemsSpinner2);
            beAdapter
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            beSpinner.setAdapter(beAdapter);

        }

        public void onNothingSelected(AdapterView<?> parent) {
            beSpinner.setAdapter(null);
        }
    }

    );
    ...
}

解决方案

In the constructor to your new ArrayAdapter on the following line:

ArrayAdapter<CharSequence> beAdapter = new ArrayAdapter<CharSequence>(this,

this points to the current instance of the OnItemSelectedListener class you are in and not the parent view, this is where the problem occurs because ArrayAdapter does not have a matching constructor. You should try using MyParentView.this (where MyParentView is the name of the view you are in) instead to pass the appropriate instance.

这篇关于Spinner2的基础上选择的微调1的动态更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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