如何从自定义视图开始一个活动自定义、视图

2023-09-12 05:09:15 作者:无处话凄凉

如何从另一个View开始一个活动(另一个活动视图)

How to start one activity from another View (another activity View)

例如,

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);   
}

我不能做此操作。因为这是视图,这是行不通的,因为视图没有 startActivity()。如何实现这一点?请给一些指导方针。

I cant do this operation. Because this is the View, that will not work, because View does not have startActivity(). How to implement this? please give some guidelines.

推荐答案

获取上下文对象,并使用其 startActivity()方法:

Obtain a Context object and use its startActivity() method:

Context context = getContext();
Intent i = new Intent(context, Screen.class);
context.startActivity(i);