开发者

Android soft keyboard and Enter action

I have a EditText in my app which is supposed to take only numeric values; this is why I set the inputType property this way:

android:inputType="number|numberSigned|numberDecimal"

It works properly, except when the user presses enter, because it losts focus; is there any property to set to avoid this? Thank you for 开发者_Go百科your answers.


What do you want to do? Keep the focus?

You can implement this method and check the value... if the value is not what you expect, you put back the focus.

public void onFocusChange(View v, boolean hasFocus) {
  // ...
}

Regarding your comment:

public void onFocusChange(View v, boolean hasFocus) {
  if (!hasFocus && (v instanceof EditText)) {
    ((EditText) v).requestFocus();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜