Anju
Anju

Reputation: 9479

EditText focus problem

I have an edit text which is placed as the first widget in my screen. So every time the page load the cursor stands inside this edit text, which I don't require. How can I remove focus from this when the page gets loaded? I tried with edittext.clearFocus(), but it didn't work out. Can anyone please reply me a solution? Thanks in advance.

Upvotes: 1

Views: 1833

Answers (2)

Waza_Be
Waza_Be

Reputation: 39538

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

This can be used to suppress the keyboard until the user actually touched the edittext view.

From Close/hide the Android Soft Keyboard:

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field.

InputMethodManager imm =
    (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.HIDE_IMPLICIT_ONLY as the second parameter to ensure you only hide the keyboard when the user didn't explicitly force it to appear (by holding down menu).

Upvotes: 2

Abhinav Saxena
Abhinav Saxena

Reputation: 19

You can have request focus in any other field, or this should not be the first field.

Upvotes: 0

Related Questions