如何从上下文中获取视图

如何从上下文中获取视图

本文介绍了android - 如何从上下文中获取视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从上下文中获取视图或 findViewById() 吗?还是出于意图?

I want to get the view or findViewById() from Context?Or from intent?

我正在尝试在我的广播接收器中访问特定视图,而 onReceive 的参数是上下文和意图.

I'm trying to reach a specific view in my broadcast receiver and the parameter of onReceive are context and intent.

嗯,我有一个类,里面有我的广播接收器.现在,我正在尝试将广播接收器与其分离,但我需要一种方法,以便我仍然可以从分离的广播接收器类中与我的类上的视图进行通信.

Well, I have a class and within it is my broadcast receiver. Now, I'm trying to separate the broadcast receiver from it, but I need a way so I can still communicate with the views on my class from my separated broadcast receiver class.

谢谢.

推荐答案

例如你可以找到任何 textView:

For example you can find any textView:

TextView textView = (TextView) ((Activity) context).findViewById(R.id.textView1);

这篇关于android - 如何从上下文中获取视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 21:42