Android RecyclerView: How to avoid scroll interruption(scroll twice) when scroll state is not IDLE? -
how avoid recyclerview being scrolled when scrollstate not idle ?
i have tried ideas overriding canscrollhorizontally()
in linearlayoutmanager
, return false
when scrollstate != idle
or same concept applied dispatchtouchevent()
in activity
, stuck screen forever.
i tried asyntask method while loop made never escape doinbackground , go onpostexercute:
@override public void onscrollstatechanged(recyclerview recyclerview, int newstate) { super.onscrollstatechanged(recyclerview, newstate); if (previousscrollstate != 0) { new asynctask<void, void, boolean>() { @override protected boolean doinbackground(void... params) { while (previousscrollstate != 0) { log.i(tag, "doinbackground " + previousscrollstate); } return true; } @override protected void onpreexecute() { super.onpreexecute(); reclist.settouchenabled(false); } @override protected void onpostexecute(boolean avoid) { super.onpostexecute(avoid); reclist.settouchenabled(true); log.i(tag, "onpostexecute " + previousscrollstate); } }.execute(); } previousscrollstate = newstate; }
my purpose avoid user skip page(scroll twice or more @ same time). how can achieve it? sharing.
not sure if bad solution before better answer come out:
@override public void onscrollstatechanged(recyclerview recyclerview, int newstate) { super.onscrollstatechanged(recyclerview, newstate); if (previousscrollstate != recyclerview.scroll_state_idle) { if (asynccheckscrollstate == null || asynccheckscrollstate.iscancelled()) { asynccheckscrollstate = new asynccheckscrollstate(); asynccheckscrollstate.execute(); } } // ... previousscrollstate = newstate; }
and:
public class asynccheckscrollstate extends asynctask<void, void, void> { @override protected void onpreexecute() { super.onpreexecute(); reclist.settouchenabled(false); } @override protected void doinbackground(void... params) { try { while (previousscrollstate != 0) { if (iscancelled()) { log.i(tag, "canceled "); break; } } } catch (exception e) { } { this.cancel(true); } return null; } @override protected void oncancelled() { super.oncancelled(); reclist.settouchenabled(true); } }
Comments
Post a Comment