【发布时间】:2012-01-03 21:27:40
【问题描述】:
我有一个带有 TextView 的 Fragment(A),使用 setText() 方法设置了值“XXXX”。我将 Fragment(A) 替换为 Fragment(B),然后再次将 B 替换为 A。
当我这样做时,Fragment(A) TextView 中的值 XXXX 消失了。我尝试在 onStart 和 onResume 方法中调用 TextView.setText 方法 - 结果相同。当我调试代码时,我可以从字面上看到正在使用的 setText 方法和值 XXXX 在那里。我在 LogCat 上打印出来了,它也在那里,但我在屏幕上看不到任何值。
我尝试用谷歌搜索,但没有得到答案。我会很感激任何指示。
代码
public void onResume() {
super.onResume();
String dData = readFileFromSDCard();
String dArray[] = dData.split(";");
txtName = (TextView) getActivity().findViewById(R.id.txtName);
txtName.setText("first name")
}
【问题讨论】:
-
请您发布一些代码。
-
我的 onResume 上有这个:
codepublic void onResume() { txtName = (TextView) getActivity().findViewById(R.id.txtName); txtName.setText("XXXX");这就是我替换的方式: DI di = new DI(); fragmentTransaction.replace(R.id.topFrame, di); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit();这是我的 xml 用户界面:codecode
标签: java android replace fragment