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

 

相关文章:

  • 2021-09-27
  • 2021-12-09
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-11-29
猜你喜欢
  • 2021-11-29
  • 2021-11-25
  • 2021-07-23
  • 2021-11-29
  • 2022-01-01
  • 2022-12-23
  • 2021-11-29
相关资源
相似解决方案