我有一个自定义 RadioButton 类,我已将它放在 Activity1 上。我正在使用它的事件“onClick”来打开另一个 Activity2。下面是代码:
public class custom_radiobutton extends RadioButton{
Paint myPaint = new Paint();
private Context cont;
public custom_radiobutton(Context context) {
super(context);
cont = context;
}
public custom_radiobutton(Context context, AttributeSet attrbs) {
super(context, attrbs);
cont = context;
}
@Override
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
String myText = (String) getText();
canvas.drawText(myText, 10, 10, myPaint);
this.setOnClickListener(radio_listener);
}
OnClickListener radio_listener = new OnClickListener() {
public void onClick(View v)
{
try
{
Intent intent = new Intent("com.moftak.db.ImageActivity");
// next line do nothing..
getContext().startActivity(intent);
// next line also not works
//cont.startActivity(intent);
}
catch(Exception ex)
{
Log.d("Image", "Error: "+ex.toString());
}
}
};
}
编辑: 问题是“getContext().startActivity(intent);”行抛出以下错误:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.moftak.db.ImageActivity (has extras) }
有人可以帮忙吗?
感谢您宝贵的时间和帮助。