Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setOnClickListener inside flipviewpager not working #5

Open
OmiAndroid opened this issue Jul 27, 2015 · 10 comments
Open

setOnClickListener inside flipviewpager not working #5

OmiAndroid opened this issue Jul 27, 2015 · 10 comments

Comments

@OmiAndroid
Copy link

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.

@shivangdoshi07
Copy link

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

@AhmedAbidii
Copy link

Anyone solve this please?

@KishorFlutter
Copy link

@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)

@tibigeorgescu90
Copy link

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

@Syex
Copy link

Syex commented Nov 9, 2015

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.

@KishorFlutter
Copy link

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; }

@hemant3370
Copy link

@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.

@digitex5
Copy link

digitex5 commented Feb 1, 2016

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.

@Ponpoorani
Copy link

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

@Ponpoorani
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants