Android remote keyboard when tapping list

In my application, I have a view with listview and searchbar to search in listview. When you click on the search bar, it gains focus and a soft keyboard appears. When I touch the list, the keyboard stays at the top of the list, so I don’t see much of my list.

My question is: How do I know if listview / ... has been touched / scrolled and how to remove the soft keyboard AND remove focus from edittext?

+8
android android-listview android-edittext
source share
3 answers

Look at this question to find out how to close the keyboard, because to check the scroll of the list you can extend the listview class and override the onScrollChanged () method and do what you want when they scroll interacts with

Edit: Actually OnScrollListener listen to scroll changes in list

+3
source share

Based on @androidnoob's answer, I am posting here (for others having this particular problem) the full code.

list.setOnScrollListener(new OnScrollListener() { public void onScrollStateChanged(AbsListView view, int scrollState) { //hide KB InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(colleagueSearch.getWindowToken(), 0); } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); 
+18
source share

yourListView.setOnScrollListener (new AbsListView.OnScrollListener () {

  @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState != 0){ InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); 
+2
source share

All Articles