hi, can someone explain to me why the first class ...
# android
j
hi, can someone explain to me why the first class which uses anymous object: implementation doesn't work but the 2nd example does work? first example shows the log message, the 2nd one doesn't, it seems like the listener isn't inside the app after compile (disclaimer i'm using r8/d8)
🤷‍♂️ 3
d
Hi, did you try doing:
Copy code
class MySampleView @JvmOverloads constructor(
        context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

    private val gestureDetector: GestureDetector
        get() = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
            override fun onDown(e: MotionEvent?): Boolean {
                return super.onDown(e)
            }
        })

    override fun onTouchEvent(event: MotionEvent?): Boolean {
        gestureDetector.onTouchEvent(event)
        return super.onTouchEvent(event)
    }
}
h
what about decompiling the APK? maybe there would you be able to see some differences in the output?
j
good suggestion, will try, thing is for some reason the annoymous classes don't always seem to work for me when setting listener, no idea why