I'm facing a weird problem when adding a ListView
to my layout.
My layout contains 2 EditText
and when I start the activity, the keyboard doesn't pop automatically. But when I add a ListView
anywhere in the layout, the keyboard pop up when the activity starts.
I know there are many ways to hide the keyboard like this one: getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
and you may have seen other solutions to the problems like here and here but my question is not how to prevent this but why is this happening ?
I have created a simple example to demonstrate this behavior
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="chadi.projects.code.TestKeyboardActivity" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@android:color/white" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
</LinearLayout>
If this ListView
doesn't exist, the keyboard don't show up. If I replace the ListView
by other views, it still doesn't show up. Only when I add a simple ListView
(even wihtout populating it with anything), is the keboard showing up.
Why is this happening?