Coding the LiveDrawingView class

Remember that LiveDrawingView cannot see the variables in LiveDrawingActivity. By using the constructor, LiveDrawingActivity is providing LiveDrawingView with a reference to itself (this) as well as the screen size in pixels contained in size.x and size.y. Add this constructor to LiveDrawingView. The code must go within the opening and closing curly braces of the class. It is convention, but not mandatory, to place constructors above other methods but after member variable declarations:

// The LiveDrawingView constructor // Called when this line: // mLiveDrawingView = new LiveDrawingView(this, size.x, size.y); // is executed from LiveDrawingActivity public LiveDrawingView(Context context, int x, int y) { // Super... ...

Get Android Programming for Beginners - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.