我使用兼容包中的 ViewPager 来分页。我想要一个后台服务,为片段提供数据。因此,我使用“普通 java 类”来更新(例如)这样一个片段中的 TextView:
public class Updater {
private Activity mActivity=null;
private TextView tv = null;
private Context mContext;
private View mInflatedMenu =null;
public Updater (Activity _activity, Context _context, View inflatedMenu) {
mActivity = _activity;
mContext = _context;
mInflatedMenu = inflatedMenu;
}
public void updateTextView (String _text) {
tv = (TextView) mInflatedMenu.findViewById(R.id.tvFragment1Updater);
tv.setText(_text);
Toast.makeText(mContext, tv.getText(), Toast.LENGTH_SHORT).show();
}
}
Toast 说, TextView 具有 parameter 的值_text
。没关系!
问题:在屏幕上 TextView 的原始值没有更改为_text
.
我想我已经尝试了各种invalidate()
. 我做错了什么?您将如何更新 ViewPager 中的片段“视图”?