i have been searching solution for this problem since two days but not succeeded yet.I have taken View pager to show details of a List view in my application, When swiped shows the details of next list item. I have the Requirement of Horizontal List view inside view pager single item.Now My problem here is When i want to swipe this Horizontal List view entire View pager item is getting Swiped, i also handled On touch event for my Horizontal List view to disallow the swipe action of View Pager but still View pager is getting swiped.Please help me, below is my 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 it is my single item of a 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 i handled touch item for 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: I am Using Fragments in My Application.Thank You
Any help would be very very very thankfull....