In my application I have a view with a listview and searchbar to search in the listview. When you tap the searchbar it gets the focus and the soft keyboard turns up. When I touch the listview the keyboard stays on top of the listview, therefore I can't see a lot of my listview.
My question: How do I know if the listview has been touched/scrolled/... and how do I remove the soft keyboard AND remove the focus from the edittext?
Based on @androidnoob answer, I post here (for the others having this specific issue) the full code needed.
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) { }
});
Take a look at this question to find out how to close the keyboard, as for knowing if the listview has been scrolled, you can extend the listview class and override the onScrollChanged() method and to do whatever you want when they scroll is interacted with
Edit: there is actually an OnScrollListener to listen for scroll changes in a listview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With