John Jared
John Jared

Reputation: 800

EditText doesn't start automatically

In my app, I have an EditText. How do I make it doesn't start automatically? Like: once they open the activity it automatically sets the mouse to the EditText and the keyboard gets opened so they type…

Is there anyway I can make it open (the keyboard shows and the user can type) when they clicks on it?

Upvotes: 1

Views: 370

Answers (2)

Archie.bpgc
Archie.bpgc

Reputation: 24012

the answer by Lucifer must work. But when i got the same problem, that solution did't work, and someone suggested me this.

add a fake layout as the first element in you parent layout and make it focusable.

Like this:

<ParentLayout
     .....
     ......>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/transparent"
        android:focusable="true"
        android:focusableInTouchMode="true" >
    </LinearLayout>

     ......
     ......
     ......

</ParentLayout>

This definitely works, but the best solution is:

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

Upvotes: 0

Lucifer
Lucifer

Reputation: 29672

Ok, so from your question i figure out that your EditText is getting focus while starting the activity. You can disable the focus using following command to suppress the keyboard.

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

Visit this Close/hide the Android Soft Keyboard

Upvotes: 1

Related Questions