如何从自定义视图启动一个活动

ios*_*per 13 android view android-intent android-activity

如何从另一个视图启动一个活动(另一个活动视图)

例如,

public class CorrectSmoothGloflo extends Activity {
  .......................
  setContentView(new Panel(this));
}


public class Panel extends View {

   //This view class contains some drawable operation
   // Here i want to start another Activity like this

   Intent i=new Intent(CorrectSmoothGloflo.this,Screen.class);
    startActivity(i);   
}
Run Code Online (Sandbox Code Playgroud)

我不能做这个操作.因为这是View,所以不起作用,因为View没有startActivity().怎么实现这个?请给出一些指导.

Kon*_*rov 27

获取Context对象并使用其startActivity()方法:

Context context = getContext();
Intent i = new Intent(context, Screen.class);
context.startActivity(i);
Run Code Online (Sandbox Code Playgroud)