Simple simple 2D graphics in a view
<p>What is the simplest way to draw pixels, lines and circles on a View?
I want to move a cross cursor around, so nothing particularly intensive.</p>

<p>I thought I could extend SurfaceView and add it to an XML and it would just work, but it just appears black, however, when I look at the layout view of localmap.xml in eclipse, the graphics appear as expected.</p>

<p>Any ideas? My onDraw is never called on the emulator, and even calling invalidate on the class makes no difference. I shall keep trying but can anyone see anything I've missed? or is there a better way entirely?</p>

<ul>
<li>Frink</li>
</ul>

<p>localmap.xml contains the following (in a RelativeLayout)</p>

<pre><code>  &lt;com.example.android.game.LocalMapView
android:id="@+id/localmap_map"
android:layout_width="fill_parent"
android:layout_above="@id/localmap_planettext"
android:layout_below="@id/header"/&gt;
</code></pre>

<p>LocalMapView.java contains the following (amongst other things)</p>

<pre><code>public class LocalMapView extends SurfaceView {

Paint mPaint = new Paint();

//Construct a LocalMapView based on inflation from XML
public LocalMapView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // allow the map to receive the focus
    setFocusable(true);
</code></pre>

<p>}</p>

<pre><code>private void drawPixel(Canvas canvas, int x, int y, int colour) {
    mPaint.setColor(colour);
    if ((x &gt;= MAP_MIN_X) &amp;&amp; (x &lt; MAP_MAX_X) &amp;&amp; (y &gt;= MAP_MIN_Y) &amp;&amp; (y &lt; MAP_MAX_Y)) {
        canvas.drawPoint(((float)x * mScaleMapToScreenX), ((float)y * mScaleMapToScreenY), mPaint);
    }
}



private void drawCircle(Canvas canvas, int x, int y, int radius, int colour) {
    mPaint.setColor(colour);
canvas.drawCircle(((float)x), ((float)y), ((float)radius), mPaint);
}




@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);       
    drawCircle(canvas, MAP_MAX_X/2, MAP_MAX_Y/2, 1, 0xFF00FFFF);
    drawPixel(canvas, MAP_MAX_X/2, MAP_MAX_Y/2, 0xFF000000);
}
</code></pre>
