这段代码无效,有什么不对?在JTextfield
被选中之前,我不想允许用户输入
radiobutton2
答案 0 :(得分:2)
4x2
答案 1 :(得分:1)
您可以尝试下面给出的代码吗?
DiscoveryEndpoint
干杯,
RENC
答案 2 :(得分:0)
你可以试试这个
检查是否选中了“Radiobutton”: isChecked()
在Android中禁用EditText: setFocusable()
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);
if (rb.isChecked()) {
t4.setFocusable(true);
} else {
t4.setFocusable(false);
}
if (rb2.isChecked()) {
t4.setFocusable(false);
} else {
t4.setFocusable(true);
}
答案 3 :(得分:0)
if (cbProhibitEditPW.isChecked()) { // disable editing password
editTextPassword.setFocusable(false);
editTextPassword.setFocusableInTouchMode(false); // user touches widget on phone with touch screen
editTextPassword.setClickable(false); // user navigates with wheel and selects widget
} else { // enable editing of password
editTextPassword.setFocusable(true);
editTextPassword.setFocusableInTouchMode(true);
editTextPassword.setClickable(true);
}
试试此代码
答案 4 :(得分:0)
问题是您在初始化视图后尚未初始化验证
在onCreate()
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);
if (rb.isChecked()) {
t4.setFocusable(true);
}
if (rb2.isChecked()) {
t4.setFocusable(false);
}
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);
}
}
});
这将限制用户在屏幕启动时输入
答案 5 :(得分:0)
解决方法是在EditText上调用setFocusable(false)
以及setEnabled(false)
。更改您的代码,如下所示:
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);
t4.setFocusable(false);
}
if(checkedId==R.id.radioButton2)
{
t4.setEnabled(true);
t4.setFocusable(true);
}
}
});