我有一个在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
对象吗?