tur*_*boy 31 android android-custom-view android-intent
我有一个自定义视图,并希望访问其活动中可用的字符串.我见过getContext()在视图类中使用的代码,但没有方法可以访问通过intent为其活动提供的String.如何使活动中的String可用于其自定义视图?
小智 38
View类中的getContext()方法返回在其构造函数上传递的上下文.通常,这是您想要的活动(活动扩展上下文).所以这可能适合你:
((Activity)getContext()).someMethod(...);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16837 次 |
| 最近记录: |