Android 动态创建编辑文本和单选按钮
如何动态创建edittext和radiobutton,以便 我可以用编辑文本书写,也可以单击单选按钮,但我应该这样做 不要两者兼而有之,那么我究竟选择了什么或写了什么答案呢 我需要存钱 我搜索它,但我没有得到任何适当的答案,请帮助我Android 动态创建编辑文本和单选按钮,android,android-edittext,textview,radio-button,checkboxlist,Android,Android Edittext,Textview,Radio Button,Checkboxlist,如何动态创建edittext和radiobutton,以便 我可以用编辑文本书写,也可以单击单选按钮,但我应该这样做 不要两者兼而有之,那么我究竟选择了什么或写了什么答案呢 我需要存钱 我搜索它,但我没有得到任何适当的答案,请帮助我 RadioButton toggleRadioButton; RadioGroup editRadiogroup = new RadioGroup(this); editRadiogroup.setOrientation(RadioGroup.HOR
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);
您好,您可以收听编辑文本上的更改: 当在编辑文本中写入文本时,可以使用toggleRadiobutton.SetVisibilityView.INVISIBLE使toggleRadiobutton不可见,或者使用toggleRadiobutton.setEnabledfalse禁用它 同样,如果检测到edittext中没有文本,可以重新启用togglebutton 使用toggleRadioButton,您将采用相同的方法。您可以在OnClickListener上检查按钮的状态,并相应地启用或禁用Edittext:
toggleRadioButton.setOnClickListener(new OnClickListener(View v){
if(((RadioButton)v).isChecked()){
edittext.setEnabled(false);
}else{
edittext.setEnabled(true);
}
});
你可以写下你的年龄?可选,或者让EditText的提示显示为可选。如果他们没有输入任何文本,他们拒绝回答。事实上,我可以用edittext写下答案,或者我可以简单地写下感谢Juan。。。。。我这样做了,而不是使用单选按钮,我用复选框,它是工作。