Android Search and Listview keybaord

125 views Asked by At

I have a simple view with a Search EditView and a ListView.

When the Activity appears, the keyboard automatically asppears with the cursor in the Search.

How do I stop it from doing that. I wish the keyboard only to appear once the user taps the search box.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
    android:id="@+id/search"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Search"
    android:inputType="text" />
<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:listSelector="@drawable/list_selector" />
</LinearLayout>
1

There are 1 answers

0
Andrei Zhukouski On BEST ANSWER

Add

android:focusable="true" 

and

android:focusableInTouchMode="true" 

elements in the parent of EditText

Must be

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="true" 
    android:focusableInTouchMode="true">
<EditText
    android:id="@+id/search"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Search"
    android:inputType="text" />
<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:listSelector="@drawable/list_selector" />
</LinearLayout>

Hope it's help