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" .

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
Cruisehu
  • 333
  • 1
  • 5
  • 12
  • try using :android:windowSoftInputMode="adjustPan" – krunal patel Jan 05 '15 at 07:01
  • Use adjustPan the titlebar will be out of the screen @krunal patel – Cruisehu Jan 05 '15 at 07:07
  • write this code on the scroll event of the listview: InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); – krunal patel Jan 05 '15 at 07:09

2 Answers2

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);
        }
    }
});
Community
  • 1
  • 1
Darpan
  • 5,623
  • 3
  • 48
  • 80
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);
Farmaker
  • 2,700
  • 11
  • 16