我需要基于 Edittext 值创建多个微调器。旋转器必须动态创建..例如,如果我在edittext 5中给出值5,则必须创建微调器...如果有人知道告诉我
答案 0 :(得分:0)
edtGiven=(EditText)findViewById(R.id.edtGiven);
btnSubmit=(Button)findViewById(R.id.btnSubmit);
final RelativeLayout layout=new RelativeLayout(this);
linear=(LinearLayout)findViewById(R.id.Linear);
StringBuffer spinnerBuffer = new StringBuffer();
final ArrayList<String> spinnerArray = new ArrayList<String>();
spinnerArray.add("1");
spinnerArray.add("3");
spinnerArray.add("4");
spinnerArray.add("5");
spinnerArray.add("6");
Spinner spinner = new Spinner(MainActivity.this);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, spinnerArray); //selected item will look like a spinner set from XML
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);
btnSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//int change=Integer.parseInt(EdtValue);
int ff=-1;
if(edtGiven.getText().toString().length()>0)
{
ff=Integer.parseInt(edtGiven.getText().toString());
}
Toast.makeText(getApplicationContext(), "btn", 1000).show();
for(int i=0;i<ff;i++)
{
Toast.makeText(getApplicationContext(), "bfor", 1000).show();
Spinner spinner = new Spinner(MainActivity.this);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_item,spinnerArray);
spinner.setAdapter(adapter);
spinner.setPrompt("works");
linear.addView(spinner);
Toast.makeText(getApplicationContext(), "bottom", 1000).show();
}
}
});
}
最后我根据来自edittext
的输入得到了创建多个微调器的答案