如何在android中执行setFocusable(false)后检索Focus

时间:2013-02-03 06:40:53

标签: android focus android-edittext

我在项目中使用了EditText。在EditText中输入值后,我想单击一个按钮。如果我单击按钮,EditText将失去它的焦点。

load.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
   description.setFocusable(false);
   }
}

如果我想更改EditText的值意味着我能做什么,我做了以下操作,但它没有用,而且它无法获得它的焦点...

focus.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
   description.setFocusable(true);
   }
}

提出任何建议来实现这一目标......

4 个答案:

答案 0 :(得分:4)

请记得致电setFocusableInTouchMode

focus.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        description.setFocusable(true);
        description.setFocusableInTouchMode(true);
        description.requestFocus(); 
    }
}

答案 1 :(得分:1)

您需要调用View.requestFocus()将焦点重新设置为EditText:

focus.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
   description.setFocusable(true);
   description.requestFocus(); //<<< get Focus on EditText
   }
}

答案 2 :(得分:0)

focus.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
   description.setFocusable(true);// or use description.setEnable(true);
   description.requestFocus(); //<<< get Focus on EditText
   }
}

答案 3 :(得分:0)

尝试方法 setEnabled(boolean b)而不是 setFocusable(boolean b)

相关问题