我的活动有两个类,如:
public class StartActivity extends Activity {
.
.
.
}
public class StartView extends View {
.
.
.
}
我想通过点击一个图像从这个Activity转到另一个。在View Class中是否有任何方法(如Activity类中的startActivity方法),我可以在第二类中使用它?
答案 0 :(得分:0)
你的意思是这样的:
public class startView extends View {
Activity mActivity;
Context mContext;
public startView(Activity yourActivity, Context context, AttributeSet attrs) {
// TODO Auto-generated constructor stub
super(context, attrs);
this.mActivity = yourActivity;
this.mContext = context;
init();
}
public void init()
{
ImageView iv = (ImageView) findViewById(R.id.IMAGEVIEWID);
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(mActivity, SecondActivity.class);
mContext.startActivity(i);
}
});
}
}