android - Viewpager disable swipe Issue when touch on Horizontal Listview inside it -
i have been searching solution problem since 2 days not succeeded yet.i have taken view pager show details of list view in application, when swiped shows details of next list item. have requirement of horizontal list view inside view pager single item.now problem here when want swipe horizontal list view entire view pager item getting swiped, handled on touch event horizontal list view disallow swipe action of view pager still view pager getting swiped.please me, below code
customviewpager.java
import com.devpoint.adapter.horizontallistview; import android.content.context; import android.graphics.rect; import android.support.v4.view.viewpager; import android.util.attributeset; import android.view.motionevent; import android.view.view; public class customviewpager extends viewpager { private boolean scrolldisable = false; public customviewpager(context context, attributeset attrs) { super(context, attrs); } @override public boolean onintercepttouchevent(motionevent ev) { if(scrolldisable) { return false; } else { return super.onintercepttouchevent(ev); } } public void disablescroll() { scrolldisable = true; } public void enablescroll() { scrolldisable = false; } }
and single item of view pager item
details_item.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ffffff" > <scrollview android:id="@+id/scrollviewid" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="2dp" > ------------------------ <android.support.v7.widget.cardview xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/cardview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="@dimen/padding_medium" android:background="#ffffff" android:clickable="true" android:orientation="vertical" android:padding="35dp" card_view:cardcornerradius="@dimen/padding_radius" > <tablerow android:layout_width="match_parent" android:layout_height="170dp" android:background="#ffffff" android:gravity="center_horizontal" android:orientation="horizontal" > <com.devpoint.adapter.horizontallistview android:id="@+id/gridview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:columnwidth="60dp" android:horizontalspacing="10dp" android:numcolumns="3" android:padding="10dp" android:stretchmode="columnwidth" android:verticalspacing="10dp" /> </tablerow> </android.support.v7.widget.cardview> </scrollview> </relativelayout>
and handled touch item horizontal listview inside adapter as
cardview.setontouchlistener(new ontouchlistener() { public boolean ontouch(view arg0, motionevent ev) { switch(ev.getaction()) { case motionevent.action_down: detailsviewpagerfragment.viewpager.disablescroll(); //enable swiping scrollview.setenabled(false); break; case motionevent.action_move: detailsviewpagerfragment.viewpager.disablescroll(); scrollview.setenabled(false); break; case motionevent.action_up: detailsviewpagerfragment.viewpager.enablescroll(); scrollview.setenabled(true); break; } return false; } });
note: using fragments in application.thank you
any very thankfull....
i face same problems yours. hope not late answer question now. way solve this:
// declare variables horizontallistview listview; viewpager viewpager; scrollview scrolllistview;
we need below variables fix issues. can call viewpager in fragment.
listview = (horizontallistview) findviewbyid(r.id.your_list_view); viewpager = (viewpager) getactivity().findviewbyid(r.id.pager); scrolllistview = (scrollview) swipeview.findviewbyid(r.id.your_scrollview_layout_id);
now implement setontouchlistener:
listview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { if (event.getaction() == motionevent.action_down) { // disable swiping of viewpager // disable scrolling of scrollview viewpager.requestdisallowintercepttouchevent(true); scrolllistview.requestdisallowintercepttouchevent(true); } return false; } });
note**:
(1) method doesn't need customise viewpager class.
(2) disable scrollview give me better scrolling performance in horizontallistview.
(3) implements setontouchlistener parent layout of horizontallistview (like did), doesn't desired result. after horizontallistview implements setontouchlistener, works well.
hopefully it's helps others too. ^^v
Comments
Post a Comment