我们可以将Relative布局对象传递给OnItemSelectedListener吗?

时间:2015-01-29 16:22:12

标签: java android spinner relativelayout onitemselectedlistener

我有一个在OnCreate方法中创建的相对布局对象。它工作正常,但我想在OnItemSelectedListener中创建一个动态微调器。

如果我创建了另一个相对布局变量,那么它就不会在OnItemSelectedListener之外呈现其他动态控件。

我的代码是:

RelativeLayout layout;
    layout = (RelativeLayout) findViewById(R.id.MultiQuesRelaLayOut);
final Spinner[] sp = new Spinner[10];
for (int a = 0; a < 2; a++) {
    sp[a] = new Spinner(this);
    RelativeLayout.LayoutParams para = new RelativeLayout.LayoutParams(
    (int) LayoutParams.WRAP_CONTENT, (int) LayoutParams.WRAP_CONTENT);
    para.leftMargin = 300;
    para.topMargin = 100;
    ArrayAdapter < String > spinnerArrayAdapter = new ArrayAdapter < String > (this, android.R.layout.simple_spinner_item, value);
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp[a].setAdapter(spinnerArrayAdapter);
    sp[a].setLayoutParams(para);
    sp[a].setTag(a);
    layout.addView(sp[a]);


    sp[a].setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView <? > arg0, View arg1,
        int pos, long arg3) {
            setContentView(R.layout.activity_questiondynamic);
            String[] DDvalue = GetDropDownvalue(Avalue);
            RelativeLayout layout = (RelativeLayout) findViewById(R.id.MultiQuesRelaLayOut);
            final Spinner[] Sp = new Spinner[10];
            int add = (int) arg0.getTag();
            Sp[add] = new Spinner(com.example.hakslogin.QuestionActivityDynamic.this);
            RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
            (int) LayoutParams.WRAP_CONTENT, (int) LayoutParams.WRAP_CONTENT);
            param.leftMargin = 25;
            param.topMargin = 200;
            Sp[add].setId(add);
            Sp[add].setLayoutParams(param);
            ArrayAdapter < String > adapter = new ArrayAdapter < String > (com.example.hakslogin.QuestionActivityDynamic.this, android.R.layout.simple_spinner_item, DDvalue);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            Sp[add].setAdapter(adapter);
            if (add == 0) {
                layout.addView(Sp[add]);
            }
        }

        @Override
        public void onNothingSelected(AdapterView <? > arg0) {
            // TODO Auto-generated method stub

        }
    });
}

我的动态控件只创建问题是相对布局如果我在项目选择事件中创建它,它不会在事件之外创建扩孔动态控件。

我可以在OnItemSelected事件中传递RelativeLayout对象吗?

0 个答案:

没有答案