jayhust

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

我们经常会在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);

 

posted on 2015-02-03 15:17  jayhust  阅读(661)  评论(0编辑  收藏  举报