其实我正在创建一个琐事应用程序。为了创建问题,我需要将选项分配给无线电组中的单选按钮,这必须动态完成。为了给出选项,我想在editText中输入选项,并在单击按钮时将其抓到单选按钮组中。必须对必须放在无线电组中的每个选项进行此操作。请帮帮我。
答案 0 :(得分:0)
RadioButton
基本上扩展了Textview
,这意味着您可以在RadioButton
的任何对象实例上调用getText()和setText (CharSequence text)
从EditText
获取文字EditText.getText().toString()
所有这些小部件的母亲都是TextView
有用??
答案 1 :(得分:0)
使用edittext.addTextChangedListener()和onaftertextchange调用radioButton.setText(edittext.getText()。toString());
代码
uid = (EditText) findViewById(R.id.ed_UserId);
radioGroup = (RadioGroup) findViewById(R.id.radioInstall);
uid.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
int selectedId = radioGroup.getCheckedRadioButtonId();
RadioButton radioButton = (RadioButton) findViewById(selectedId);
radioButton.setText(uid.getText().toString());
if (radioButton.getText().equals("Install Now")) {
Toast.makeText(getApplicationContext(),
radioButton.getText(), Toast.LENGTH_SHORT).show();
} else
Toast.makeText(getApplicationContext(),
radioButton.getText(), Toast.LENGTH_SHORT).show();
}
});