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