5

The xml is as follow.

enter image description here

I want to implement the function like this: when I click the edittext, the soft input show. when I scroll(not scroll to OnScrollListener.SCROLL_STATE_IDLE state) the listview the soft input hide.

I use the android:windowSoftInputMode="adjustResize" .

3
  • try using :android:windowSoftInputMode="adjustPan" Commented Jan 5, 2015 at 7:01
  • Use adjustPan the titlebar will be out of the screen @krunal patel Commented Jan 5, 2015 at 7:07
  • write this code on the scroll event of the listview: InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); Commented Jan 5, 2015 at 7:09

2 Answers 2

11

Detect your scroll using this link, it implements onScrollListener, which you will set to your ListView and in its onScrollStateChanged() you will 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);
        }
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

I kept getting errors with this. Then I restarted Android Studio and reopened my project and all worked well. Android Studio can be buggy that way.
requires API 23+
1
InputMethodManager inputMethodManager = (InputMethodManager) 
           getSystemService(Activity.INPUT_METHOD_SERVICE);     
           inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(‌​), 0);

gives a bug in AS... Use this instead inside onScrollStateChange

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.