1

I have an Activity, which has an EditText and a ListView. The EditText can be used to filter listview rows.

problem is that when the Activity loads up, the keyboard popups by default. I would want that the keyboard come up only when a user actualy taps into the text box and not by default.

Public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.filterablelayout);

    filterText = (EditText) findViewById(R.id.search_box);
    filterText.addTextChangedListener(filterTextWatcher);

    filterText.setVisibility(View.INVISIBLE);

    GetCategories();
}

My layout xml is as below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/selectcat" />

<EditText
    android:id="@+id/search_box"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/categorytxthint"
    android:inputType="text"
    android:maxLines="1" />

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1" />

</LinearLayout>
Saurabh Kumar
  • 2,329
  • 6
  • 32
  • 52
  • I think this issue is resolved by http://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup. Testing now. – Saurabh Kumar Feb 05 '12 at 06:42

2 Answers2

0

I've had this problem myself, its really annoying. You need to tell the system to hide the Soft Keyboard. The Android documentation says this, "Flag for hideSoftInputFromWindow(IBinder, int) to indicate that the soft input window should only be hidden if it was not explicitly shown by the user."

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
Spidy
  • 39,723
  • 15
  • 65
  • 83
0

In the manifest, put the following for your activity :

android:windowSoftInputMode="stateHidden"
LoveAndCoding
  • 7,857
  • 2
  • 31
  • 55
azfar
  • 129
  • 1
  • 3