Custom List Using EditText: Focus

I have a simple layout with EditText and Listview. An implemented custom ArrayList adapter to populate the list and a custom filter so that the user can search for items displayed in the list.

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

  • When the application starts, the focus should be set to ListView.
  • If the user wants to enter text by selecting the edittext control, a keyboard appears.
  • (At this point, when the user enters text, the list items will change - I already turned this on)
  • If the keyboard is still open, if the user selects an item in the list, the keyboard should disappear and call the listview onItemClick function.

How can i do this?

+4
source share
1 answer

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

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

2. Then in Activity add:

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

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1443161/


All Articles