Member-only story

Android Touch System — Part 3: MotionEvent Listeners

Sherry Yuan
ProAndroidDev
Published in
5 min readApr 18, 2022
Photo by Ilyuza Mingazova on Unsplash

This is Part 3 of my Android Touch System series. Parts 1 and 2 take a deep dive into touch functions (onDispatchTouchEvent(), onInterceptTouchEvent(), onTouchEvent()) and how touch events flow through the view hierarchy. This post will cover the main event listeners provided by the View class, as well as standalone gesture detector classes.

Table of Contents

Why Use Listeners?

Most listener interfaces correspond one-to-one with a function in the view class — for example OnTouchListener with onTouchEvent() — so when should we use a listener instead of overriding the function directly? There are three considerations:

  1. Using a listener allows handling touch events without creating a new custom view. If a view has everything you need except event-handling, it’s less verbose to add a listener to your instance of it rather than extending it. For example, if you want a specific TextView to open a screen when clicked, setting an OnClickListener would be…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Sherry Yuan

Android engineer @ Cash App (she/her) • Find my sci-fi/fantasy short stories at sherryyuan.substack.com

Responses (1)

What are your thoughts?

Зачем платно сделали? Это издевательство какое-то

--