Hide soft input when scrolling through a list

xml is as follows.

enter image description here

I want to implement such a function: when I click on edittext, a soft input image is displayed. when I scroll (does not scroll to the OnScrollListener.SCROLL_STATE_IDLE state), the list hides hidden input.

I am using android:windowSoftInputMode="adjustResize" .

+5
source share
2 answers

Find your scrolling using this link , it implements onScrollListener , which you install on your ListView , and in onScrollStateChanged() you put this code in your

 setOnScrollListener(new OnScrollListener(){ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // TODO Auto-generated method stub } public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState !=0){ InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(‌​), 0); } } }); 
+10
source
 InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(‌​), 0); 

gives an error in AS ... Use this instead inside onScrollStateChange

 InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow(absListView.getApplicationWindowToken(), 0); 
+1
source

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


All Articles