Question

Je suis en train d'ajouter un ImageView personnalisé à mon main.xml, mais si je lance le programme, il se ferme avec un proche forcé.

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="@drawable/background" >

     <test.testpkg.CustomImageView
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_gravity="center_vertical"
          android:src="@drawable/bg"/>

</LinearLayout>

Java:

package test.testpkg;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.widget.ImageView;

public class CustomImageView extends ImageView {

    public CustomImageView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}

Aussi, si je commence le programme Débogueur après le FC Je ne reçois ceci: Le texte du lien

Était-ce utile?

La solution

Debugger ne sert à rien si vous ne l'avez pas attaché le code source d'Android. De plus ... il est plus utile de fournir la sortie logcat. Quoi qu'il en soit, je pense que vous manquez un des constructeurs. Essayez ceci:

public class CustomImageView extends ImageView {

 public CustomImageView(Context context) {
  super(context);
  // TODO Auto-generated constructor stub
 }

 public CustomImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
 }
 // rest of your code....
scroll top