-2
我需要創建多個微調框根據EditText value.An微調框必須動態創建..例如,如果我在edittext中給出值5 5微調框必須是created..if誰知道告訴我如何根據用戶輸入創建一個微調框在android中
我需要創建多個微調框根據EditText value.An微調框必須動態創建..例如,如果我在edittext中給出值5 5微調框必須是created..if誰知道告訴我如何根據用戶輸入創建一個微調框在android中
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上
Upadate微調適配器創建基於我輸入多微調。請參閱http://www.edureka.co/blog/custom-spinner-in-android –
,但微調控件不會在該頁面上動態創建 –