cymcsg / UltimateRecyclerView

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
Apache License 2.0
7.22k stars 1.43k forks source link

UltimateRecyclerView不能setOnTouchListener #287

Open OVERSKY2003 opened 8 years ago

OVERSKY2003 commented 8 years ago

我想实现滑动RecyclerView是收起键盘,发现setOnTouchListener无效,代码如下:

@Bind(R.id.recycler_view)
UltimateRecyclerView mRecyclerView;

mRecyclerView.setOnTouchListener(new MyOnTouchListener());

public final class MyOnTouchListener implements View.OnTouchListener {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
            hideSoftKeyboard();
        }
        return false;
    }
}
jjhesk commented 8 years ago

there is another handler that does it think. The current touchevent is blocked from the view.

OVERSKY2003 commented 8 years ago

那我要如何做,才能实现点击或者滑动RecyclerView,收起键盘的功能?

OVERSKY2003 commented 8 years ago

@jjhesk,what is another handler so that I can setOnTouchListener on UltimateRecyclerView?

OVERSKY2003 commented 8 years ago

I used setScrollViewCallbacks and hide keybroad when onScrollChanged. It works

jjhesk commented 8 years ago

@OVERSKY2003 interesting solution. can u post out and share the code with us?

OVERSKY2003 commented 8 years ago
    mRecyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
        @Override
        public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
            hideSoftinput(mMobile);

        }

        @Override
        public void onDownMotionEvent() {
            hideSoftinput(mMobile);

        }

        @Override
        public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {

        }
    });