4

I have a simple layout with EditText and a Listview. Implemented custom ArrayList adapter to fill in the listview and custom filter so user can search for items displayed in the listview.

When I run the application, the focus is initially set to EditText and the keyboard is displayed as expected. But here is what I want to do:

  1. The focus should be initially set to ListView when the app is launched.
  2. If the user wants to enter text by selecting edittext control, then the keyboard should appear.
  3. ( At this point as the user inputs text, the listview items will change - I already implmented this)
  4. With the keyboard still open, if the user select an item in the listview, the keyboard should disappear and trigger the listview onItemClick function.

How can I accomplish this?

Bart
  • 19,692
  • 7
  • 68
  • 77

1 Answers1

1

1.Add below attribute to your particular EditText in its layout-xml:

android:focusable="false"
android:focusableInTouchMode="true"

2.Then in your Activity add:

mEditText.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        v.setFocusable(true);
        return false;
    }
});

Hope this helps.

Gagan
  • 1,497
  • 1
  • 12
  • 27
  • 1
    Thank you. With above solution the EditText is not getting focus at all. Unable to click on it and get the Keyboard. – user1787709 Oct 31 '12 at 16:16