O'Reilly logo

Android Programming: The Big Nerd Ranch Guide, Third Edition by Kristin Marsicano, Chris Stewart, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

31 Custom Views and Touch Events

In this chapter, you will learn how to handle touch events by writing a custom subclass of View named BoxDrawingView. The BoxDrawingView class will be the star of a new project named DragAndDraw and will draw boxes in response to the user touching the screen and dragging. The finished product will look like Figure 31.1.

Figure 31.1  Boxes drawn in many shapes and sizes

Screenshot shows DragAndDraw in Android phone. The screen shows Boxes drawn in many shapes and sizes.

Setting Up the DragAndDraw Project

Create a new project named DragAndDraw. Select API 19 as the minimum SDK and create an empty activity. Name the activity DragAndDrawActivity.

DragAndDrawActivity will be a subclass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required