zoukankan      html  css  js  c++  java
  • android onclick onLongClick ontouch dispatchTouchEvent onInterceptTouchEvent

    android onclick onLongClick ontouch dispatchTouchEvent onInterceptTouchEvent

    按ACTION_DOWN -> onLongClick -> ACTION_UP -> onClick的次序发生的

    onTouchevent() vs onTouch()

    onTouch() is used by users of the View to get touch events while onTouchEvent() is used by derived classes of the View to get touch events.

    1) Implementation:

    If you want use onTouch() you have to do three things.

    1- implement OnTouchListener

    2- call setOnTouchListener() on the view you want to set catch the event

    3- override onTouch() to handle the event

    but if you want to use onTouchEvent() you don't need to do step 1 & 2 above. just you need to override onTouchEvent().

    2) Working:

    onTouch() works on view, viewgroup, activity. Meaning you can use onTouch() inside view, viewgroup or activity. This methods take two arguments [onTouch(View v, MotionEvent e) ]. This allows you filter events for different views in an activity or view group. Or the activity can itself handle it. onTouchEvent() takes on one argument [onTouchEvent(MotionEvent e) ]. Thus this can be used only inside the view that implements it or on the derived view.

    I think, such options are part of Android's more flexible development philosophy, though it creates confusion for the learners at times.

  • 相关阅读:
    POJ 1141 括号匹配 DP
    881. Boats to Save People
    870. Advantage Shuffle
    874. Walking Robot Simulation
    文件操作
    861. Score After Flipping Matrix
    860. Lemonade Change
    842. Split Array into Fibonacci Sequence
    765. Couples Holding Hands
    763. Partition Labels
  • 原文地址:https://www.cnblogs.com/ZacharyHodgeZou/p/3854808.html
Copyright © 2011-2022 走看看