14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: Creating User Interfaces<br />

94<br />

Figure 4-3<br />

1. Create a new Compass project that will contain your new Compass View, and an Activity to<br />

hold it. Now create a new CompassView class that extends View. Create constructors that will<br />

allow the View to be instantiated in code, or through infl ation from a resource layout. Add a<br />

new initCompassView method that will be used to initialize the control and call it from each<br />

constructor.<br />

package com.paad.compass;<br />

import android.content.Context;<br />

import android.graphics.*;<br />

import android.graphics.drawable.*;<br />

import android.view.*;<br />

import android.util.AttributeSet;<br />

import android.content.res.Resources;<br />

public class CompassView extends View {<br />

public CompassView(Context context) {<br />

super(context);<br />

initCompassView();<br />

}<br />

public CompassView(Context context, AttributeSet attrs) {<br />

super(context, attrs);<br />

initCompassView();<br />

}<br />

public CompassView(Context context,<br />

AttributeSet ats,<br />

int defaultStyle) {<br />

super(context, ats, defaultStyle);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!