首页 > 移动平台 > 详细

Android之在View中执行Activity的跳转

时间:2015-02-03 16:34:53      阅读:230      评论:0      收藏:0      [点我收藏+]

我们经常会在Activity中用到继承LinearLayout或者其他布局的View,但是又想在View的代码里面去执行

Activity的跳转,直接使用startActivity会报错,那么就要用到getContext()来“Returns the context

the view is running in, through which it can access the current theme, resources, etc.”

示例代码如下:

// 跳转到相应的Activity
Intent intent1 = new Intent();
intent1.setClass(getContext(), LocationSelectActivity.class);
getContext().startActivity(intent1);

 

Android之在View中执行Activity的跳转

原文:http://www.cnblogs.com/jayhust/p/4270097.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!