Yalantis/FlipViewPager.Draco

setOnClickListener inside flipviewpager not working

OmiAndroid opened this issue · 10 comments

I am trying to implement this in one of my project but the views coming after flip are no taking OnClickListener event.
For example textviews after flip the image not taking clicklisener event
Please help to sort out this.

Hey Omi,
I am facing the same issue. I am adding custom text view when the page is flipped but I am not able to input/select anything in the textview. Also, I added a button but it's not clickable.
Where you able to find any solution to this?
Thanks

Anyone solve this please?

@ShivDoshi @OmiAndroid @Aabidi09
Yah I did this, follow this procedure...

  1. Comment all OnInterceptTouchEvent in FlipViewpager.java

  2. Replace following methods with code given here
    private boolean flipped=false;
    public void flipToPage(int page) {
    int delta = page * FLIP_DISTANCE - (int) mFlipDistance;
    endFlip();
    mScroller.startScroll(0, (int) mFlipDistance, 0, delta, getFlipDuration(delta));
    invalidate();
    flipped=!flipped;
    }

       @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
              if(flipped){
              return false;
              }else{
               return true;
        }
       }
  1. Register OnClickListeners on views in fillHolder() of your adapter (adapter that extends BaseFlipAdapter)

@KishorAndroid your solution denies the user to possibility to close the filpview once opened

Syex commented

I think I found a solution:

Modify FlipViewPager.onInterceptTouchEvent() as following:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
        View view = mCurrent.pageView;
        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                View childView = viewGroup.getChildAt(i);
                if (childView.isClickable() && isPointInsideView(ev.getRawX(), ev.getRawY(), childView)) {
                    return false;
                }
            }
        }
       // rest of the method as it is
}

with

private boolean isPointInsideView(float x, float y, View view) {
        int location[] = new int[2];
        view.getLocationOnScreen(location);
        int viewX = location[0];
        int viewY = location[1];

        //point is inside view bounds
        return (x > viewX && x < (viewX + view.getWidth())) &&
                (y > viewY && y < (viewY + view.getHeight()));
    }

This will simply check if there was a e.g. a button clicked and will return false therefore, so the button gets the event.

Try this... working well for me

@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if(flipped){ return false; }else{ return true; } }

private boolean flipped=false; public void flipToPage(int page) { int delta = page * FLIP_DISTANCE - (int) mFlipDistance; endFlip(); mScroller.startScroll(0, (int) mFlipDistance, 0, delta, getFlipDuration(delta)); invalidate(); Log.d("FlipDistance", "delta " + delta + " mFlipDistance " + mFlipDistance); if(delta <=0 && delta >-90){ flipped=false; Log.d("FlipDistance", "Flipped Cancel"); return; } if(delta >=0 && delta < 90){ flipped=false; Log.d("FlipDistance", "Flipped Cancel"); return; } flipped=!flipped; }

@KishorAndroid
It works sometime even when the view is not flipped . I mean the buttons on the flipped view are responding even when not in view.

I managed to solve this with the code given in this link. (The answer is in the comments).
http://android-delight.blogspot.in/2015/04/flipviewpager-in-list-view.html

But as mentioned above, buttons can be clicked even if the view is not flipped. This means that user is able to click unseen buttons. Is there a way to eliminate this problem. Thanks in advance.

@KishorAndroid I followed your steps but Its not working for me. Please help!

@digitex5 I followed the post but it still didnt work. Am i missing something?