我试图禁用并启用edittext框的聚焦取决于复选框。选中复选框时,文本框可以对焦,如果未选中,则文本框应该是不可聚焦的。当我尝试使用复选框禁用文本框后启用对焦文本框时,它不起作用。这是我的代码。
check_box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
txt_time.setFocusable(true);
} else {
txt_time.setFocusable(false);
}
}
});
提前致谢..
答案 0 :(得分:1)
试
启用:
txt_time.setFocusableInTouchMode(true);
txt_time.setFocusable(true);
禁用:
txt_time.setFocusableInTouchMode(false);
txt_time.setFocusable(false);
而不是
启用:
txt_time.setFocusable(true);
禁用:
txt_time.setFocusable(false);
答案 1 :(得分:0)
而不是
txt_time.setFocusable(true);
试
txt_time.setEditable(true);