我有2个标签的FragmentTabHost。 每个片段(标签)都需要从互联网加载数据并显示它。
如果我在onCreate上加载数据并填充它然后切换到另一个选项卡然后我有空视图。
TextView emailView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View convertView = inflater.inflate(R.layout.contactdetails_pro, container, false);
emailView = (TextView) convertView.findViewById(R.id.contactdetails_info_email);
return convertView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String id = getArguments().getString("id");
MyTask pdthread = new MyTask(this.getActivity(), id, new AsyncTaskCompleteListener() {
@Override
public void onComplete(Detail detail) {
emailView.setText(detail.getEmail());
}
});
pdthread.execute();
}
答案 0 :(得分:0)
我对FragmentTabHost
不熟悉,但您可以尝试这一点(注意:您可能需要制作Detail
类工具Serializable
):
Detail mDetail = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String id = getArguments().getString("id");
if (savedInstanceState == null) {
MyTask pdthread = new MyTask(this.getActivity(), id, new AsyncTaskCompleteListener() {
@Override
public void onComplete(Detail detail) {
mDetail = detail;
emailView.setText(mDetail.getEmail());
}
});
pdthread.execute();
} else {
mDetail = (Detail)savedInstanceState.getSerializable("detail");
if (mDetail ! = null) {
emailView.setText(detail.getEmail());
}
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("detail", mDetail);
}