I have a ViewPager that contains a ListFragment
with a TouchListener
(SwipeDismissListViewTouchListener). I modified the ViewPager
like this:
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
private boolean pagingEnabled = true;
public void setPagingEnabled(boolean enabled) {
pagingEnabled = enabled;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (!pagingEnabled) {
return false; // do not intercept
}
return super.onInterceptTouchEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!pagingEnabled) {
return false; // do not consume
}
return super.onTouchEvent(event);
}
}
And I disable the swipe of the ViewPager
from the onOptionsItemSelected
in the ListFragment
method.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_edit) {
CustomViewPager vp = (CustomViewPager) getActivity().findViewById(R.id.pager);
vp.setPagingEnabled(false);
getListView().requestDisallowInterceptTouchEvent(true);
}
return super.onOptionsItemSelected(item);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SwipeDismissListViewTouchListener touchListener =
new SwipeDismissListViewTouchListener(
getListView(),
new SwipeDismissListViewTouchListener.DismissCallbacks() {
@Override
public boolean canDismiss(int position) {
return true;
}
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
removeItem(position);
}
}
}
);
getListView().setOnTouchListener(touchListener);
// Setting this scroll listener is required to ensure that during ListView scrolling,
// we don't look for swipes.
getListView().setOnScrollListener(touchListener.makeScrollListener());
}
The swipe of the ViewPager
is disabled but the problem that I can not running the SwipeDismissListViewTouchListener
.
I have tested these answers but do not work me
Nesting Android ViewPager, Swiping ListItems inside a ListView horizontally
ViewPager intercepts all x-axis onTouch events. How to disable?
Capture swipe to dismiss listview gestures in ViewPager
Any solution? Thanks
I found solution for my error. In this question I answer how disable onClick method in Fabric library. Can I set custom onClick on my timeline using fabric sdk?
The project is same the project is the same and this related error. In this method disable views,clickable and long clickable:
and disable method to swipe2dismiss
The solution is add on list adapter this lines:
view.setEnabled only not works. You must add view.setClickable(false). Why? I don't know but it works.
Thanks for the help