如何正确扩展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
}
}
我在XML中插入了DialButton(不必担心文件的其余部分,它无关紧要)
<?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组件使应用程序崩溃?
没有找到相关结果
已邀请:
1 个回复
豆兢