Android: can't create custome ViewGroup to make google map rotate
<p>i'm trying to make an app making the same thing google map does, it suppose to rotete the map according to the compass (e.g. if i turn west i want my top image of the map point west by rotation).
i saw this thread  <a href="http://stackoverflow.com/questions/1830391/rotate-mapview-in-android">Rotate MapView in Android</a>
and understand that i need to do custom view that extands ViewGroup so i did. and in this class i ipmplement dispatchdraw. but when i execute the app it gives "can't inflate" error of some kind.</p>

<p><strong>the xml file of the main program is:</strong> (MapWrapper is my custom view that extends ViewGroup</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" &gt;

 &lt;LinearLayout ........&gt; ... &lt;/LinearLayout

&lt;com.finalproject.minimap.MapWrapper 
    android:id="@+id/mapwrapper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"&gt;

&lt;com.google.android.maps.MapView android:id="@+id/mapview"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:clickable="true"
         android:apiKey="09mjKWsWcwRgqiP3CsLBL1TcXUapAg9pNTYNkZQ"/&gt;
&lt;/com.finalproject.minimap.MapWrapper&gt;  
&lt;/LinearLayout&gt;
</code></pre>

<p><strong>The MapWrapper class is :</strong></p>

<pre><code>package com.finalproject.minimap;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.ViewGroup;


public class MapWrapper extends ViewGroup {

static Boolean compass;
static float[] values;

//constructor
MapWrapper(Context context, AttributeSet attrs){
    super(context, attrs);
    compass = false;
}

//constructor
public MapWrapper(Context context) {super(context);}


void setCompassChanged(Boolean answer){
    compass = answer;
}


void setAzimuthValue(float[] t_values){
    values = t_values;
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // TODO Auto-generated method stub

}

@Override
 protected void dispatchDraw(Canvas canvas) {
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    if (compass) {
        compass =false;
        // rotate the canvas with the pivot on the center of the screen
        canvas.rotate(-values[0], getWidth() * 0.5f, getHeight() * 0.5f);
        super.dispatchDraw(canvas);
        canvas.restore();
    }
}
}
</code></pre>

<p>and from the main program i am trying to call the MapWrapper using findViewById(R.id.mapwrapper)</p>

<p><strong>this is a part of the main class:</strong></p>

<pre><code>public class MinimapCreateActivity extends MapActivity {

private MapView map_view;
private MapController map_controller; 
private MyLocationOverlay where_am_i = null;
private LocationManager loc_mgr = null;
private SensorManager sensor_mgr; //use for compass
private Sensor sensor;
private float[] compass_values;
boolean compass = false;
MapWrapper mw;

    private SensorEventListener sensor_event_listener  = new SensorEventListener (){

    public void onSensorChanged(SensorEvent event) {
        MapWrapper.compass = true;
        MapWrapper.values = event.values;
    }
    public void onAccuracyChanged(Sensor sensor, int accuracy) {}
};


    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.minimap_create);
    ....
    ....
    sensor = sensor_mgr.getDefaultSensor(Sensor.TYPE_ORIENTATION); 
    mw = (MapWrapper)findViewById(R.id.mapwrapper);  &lt;==i think here is the problam

}

public void onResume()
{
    super.onResume();
    .......
    sensor_mgr.registerListener(sensor_event_listener , sensor    ,SensorManager.SENSOR_DELAY_NORMAL);


}
</code></pre>

<p>byw - i don't understand something, if the compass send me oriantaion changes and i implement dispatchDraw, how is dispatchDraw knows when to update itself? how can i call it manually (should i just call it? it seems wierd cause android built in almost everything but this one.)</p>

<p>thanks all</p>
