在禁用android中的编辑文本框后,启用Focusable of edit textbox依赖于复选框无效

时间:2012-05-08 06:58:27

标签: android

我试图禁用并启用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);
                }

            }
        });

提前致谢..

2 个答案:

答案 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);