我有一个 Activity ,通常我会抓取一个 TextView ,然后我有一个单独的类需要该 TextView 来修改它
//textview
this.tvUpdate = (TextView) findViewById(R.id.tvUpdate);
new GetData(context,params,method,preText);
我想在单独的类中获得相同的 View ,而不必在构造函数中传递它。
public class GetData {
private ProgressBar pbTitle;
private TextView tvUpdate;
private Context context;
private String preText,method;
private String[] params;
public void getData(Context context,String[] params, String method,String preText){
this.context = context;
//how do i get this text view?
this.tvUpdate = ???
this.params = params;
this.method = method;
}
}
不确定这是否可行。
编辑工作代码行
tvUpdate = (TextView) ((Activity) context).findViewById(R.id.tvUpdate);
最佳答案
这可能有用。
this.tvUpdate = ((YourActivity) context) findViewById(R.id.tvUpdate);
关于java - 如何通过 Activity 的上下文获取类中的 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8161740/