Как правильно расширить ImageButton?

Я хочу расширить функциональные возможности класса ImageButton в новом классе, который я выбрал для вызова «DialButton». Для начала я просто расширил ImageButton и ничего нового не добавил. На мой взгляд, он должен быть идентичен обычному классу ImageButton.

package com.com.com;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageButton;

public class DialButton extends ImageButton{

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

    public DialButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public DialButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

}

Я вставляю DialButton в XML (не беспокойтесь об остальной части файла, это не имеет значения)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">
    <TableRow
    android:layout_weight="1">
        <DialButton
            android:id="@+id/button1"
            android:background="@drawable/dialpad"
            android:layout_weight="1"/>

И использую XML в своей деятельности:

package com.com.com;

import android.app.Activity;
import android.os.Bundle;

public class Android3 extends Activity {

    DialButton button1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.maintable);   
    }
}

Все компилируется и устанавливается в эмуляторе, но когда приложение запускается, оно закрывается для меня. Если я изменю компонент XML с DialButton на ImageButton, все будет работать нормально. Почему это? В чем разница между классом ImageButton и моим классом DialButton, из-за которого компонент DialButton вызывает сбой приложения?

8
задан fred 12 June 2011 в 21:44
поделиться