滚动列表时隐藏输入框

来源:互联网 发布:VH软件 编辑:程序博客网 时间:2024/06/05 09:25

hide soft input when listview scroll

在需要滚动列表时,隐藏输入框,其实是要给listview增加onscroll回调即可

问题:

布局如下:

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 toOnScrollListener.SCROLL_STATE_IDLE state) the listview the soft input hide.

我想实现这样的功能:

当我点击输入框时,输入框出现。当我滚动列表时,输入框消失。

I use the android:windowSoftInputMode="adjustResize" .

我已经增加了android:windowSoftInputMode="adjustResize" .

建议答案:

Detect your scroll using this link, it implements onScrollListener, which you will set to yourListView and in its onScrollStateChanged() you will put this code in your -  

检测滚动使用this link,它实现了onScrollListener。

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);        }    }});


0 0
原创粉丝点击