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?

2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. With above solution the EditText is not getting focus at all. Unable to click on it and get the Keyboard.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.