此代碼無法正常工作,錯在哪裏?我不希望允許用戶輸入直到radiobutton2
檢查禁用與單選按鈕檢查EditText
EditText t4 = (EditText)findViewById(R.id.editText3);
RadioButton rb = (RadioButton) findViewById(R.id.radioButton1);
RadioButton rb2 = (RadioButton) findViewById(R.id.radioButton2);
RadioGroup rg =(RadioGroup) findViewById(R.id.G1);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId==R.id.radioButton1)
{
t4.setEnabled(false);
}
if(checkedId==R.id.radioButton2)
{
t4.setEnabled(true);
}
}
});
在Android中禁用edittext有點麻煩。嘗試添加't4.setFocusable(false);'結合't4.setEnabled(false);' –
http://stackoverflow.com/a/23197277/7320259希望它可以幫助您 –