I can't figure out what's wrong with the code.. I tried several different things and nothing works.. So I have a class that extends a View because I need to do my own onDraw, and an xml where that custom view is placed. Ok so here's the code..
mainimagehandler.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<net.stojakovic.example.ImageMainHandler.Panel
android:id="@+id/custom_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
and the activity with the custom view
package net.stojakovic.example;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import com.actionbarsherlock.app.SherlockActivity;
public class ImageMainHandler extends SherlockActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mainimagehandler);
}
public static class Panel extends View {
public Panel(Context context) {
super(context);
Log.w("Panel","constructor");
}
public Panel(Context context, AttributeSet attrs){
super(context, attrs);
}
@Override
public void onDraw(Canvas canvas) {
Log.w("Panel","onDraw");
}
}
}
When I do it like this the app crashes with the LogCat message:
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.stojakovic.example/net.stojakovic.example.ImageMainHandler}: android.view.InflateException: Binary XML file line #8: Error inflating class net.stojakovic.example.ImageMainHandler.Panel
When I define the custom view in the xml like this, the app doesn't crash but nothing happens, the constructors don't get called
<View
class="net.stojakovic.example.ImageMainHandler.Panel"
android:id="@+id/custom_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>