【发布时间】:2014-06-16 17:48:02
【问题描述】:
我怎样才能动态创建edittext和radiobutton,这样要么 我可以在edittext中写,也可以单击单选按钮,但我应该 不要两者都做,然后我选择或写下答案 我需要保存。
我正在搜索它,但我没有得到任何合适的答案,请帮助我!
RadioButton toggleRadioButton;
RadioGroup editRadiogroup = new RadioGroup(this);
editRadiogroup.setOrientation(RadioGroup.HORIZONTAL);
LinearLayout editlayout=new LinearLayout(this);
editlayout.setOrientation(LinearLayout.HORIZONTAL);
try
{
for (int i = 0; i < answer.length; i++)
{
int id = Integer.parseInt(5+ "" + i);
// add edit text
EditText editText;
editText = new EditText(this);
editText.setMaxLines(1);
editText.setGravity(Gravity.LEFT);
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setId(id);
editlayout.addView(editText, WrapWidth, WrapHeight);
TextView tv = new TextView(this);
tv.setTextColor(Color.BLACK);
tv.setTextSize(18);
tv.setText("Year" +" " +"(or)"+" ");
editlayout.addView(tv);
// add radio button
toggleRadioButton = new RadioButton(this);
toggleRadioButton.setChecked(false);
toggleRadioButton.setTextSize(15);
toggleRadioButton.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
editRadiogroup.addView(toggleRadioButton,WrapWidth1,WrapHeight);
【问题讨论】:
-
您可以只写“你的年龄是多少?(可选)”,或者让 EditText 的提示说“可选”。如果他们没有输入任何文字,他们就拒绝回答。
-
其实我可以在edittext中写下答案,也可以直接拒绝
标签: android android-edittext textview radio-button checkboxlist