简体   繁体   中英

Android onTouchListener with ImageView and PDFRenderer

Can some body help me with some understanding about onTouchListners ?? I am new to android...and doing something more complex I guess..

1. I have a main Activity class which renders a list of 7 pdf files

2. there exists a PDF class which renders the selected item as a new pdf file(done using pdf renderer)

3. there exists a flip class to take care of flipping pages on touch

I am confused about, where to place the following method as it is never getting called if placed correctly and it shud help me deliver the next or previous pdf page..

public boolean onTouch(View v, MotionEvent event) {
         return gDetector.onTouchEvent(event);
   }

Thank u..

Here is a simple explanation of how OnTouch works...

public boolean onTouch(View v, MotionEvent event) {

    int action = MotionEventCompat.getActionMasked(event);
    int pointerIndex = MotionEventCompat.getActionIndex(event);
    int x = (int)MotionEventCompat.getX(event,pointerIndex);
    int y = (int)MotionEventCompat.getY(event,pointerIndex);

    switch(action)
    {
    case MotionEvent.ACTION_DOWN:
        //
        // First finger was touched. Set "pointerIndex" to some value (lets say 0 or -1)
        // Save "pointerIndex" corresponding to this touched object.
        //
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        //
        // More finger touched when first finger is already touched.
        // Save "pointerIndex" corresponding to this touched object.
        //
        break;
    case MotionEvent.ACTION_MOVE:
        //
        // Finger with "pointerIndex" was moved.
        //
        break;
    case MotionEvent.ACTION_UP:
        //
        // The first touched finger went off.
        //
        break;
    case MotionEvent.ACTION_POINTER_UP:
        //
        // Finger with "pointerIndex" went off (other than first finger)
        //
        break;
    }
    return true;
}

I hope this helps.

Good Luck. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM