2011-11-17 20 views
0

我有,我抢到一个TextView normallythen我有一个单独的类这就是一个活动的情况下需要一个TextView的修改它如何抢在一个类中一个TextView通过活动

//textview 
this.tvUpdate = (TextView) findViewById(R.id.tvUpdate); 

new GetData(context,params,method,preText); 

我想这个相同的视图在一个独立的类中,而不必在构造函数中传递它。

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); 

回答

2

编辑工作线这可能工作。感谢

this.tvUpdate = ((YourActivity) context) findViewById(R.id.tvUpdate); 
1
LayoutInflater inflater = LayoutInflater.from(context); 
View yourView = inflater.inflate(R.layout.yourlayout, null); 
this.tvUpdate = (TextView) yourView.findViewById(R.id.tvUpdate); 
+0

作品... – Brian

+0

高兴它的工作.... – Rakhita

+0

其实还是有一些问题。代码没有任何错误,但我无法操作视图。 – Brian

相关问题