如何从自定义视图开始一个活动 [英] How to start one activity from Customized View

查看:92
本文介绍了如何从自定义视图开始一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从另一个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);

这篇关于如何从自定义视图开始一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆