1 回答
![?](http://img1.sycdn.imooc.com/545845b40001de9902200220-100-100.jpg)
TA贡献1841条经验 获得超3个赞
我很久以前就遇到过这个问题:/但我找到了解决问题的简单方法:)
用这个来解决问题:
// Necessary :)
private Context mContext;
private View MyView;
// Nullable
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mContext=getActivity();
if(MyView==null){
// Layout View
MyView=LayoutInflater.from(mContext).inflate(R.layout.fragment_profile, null);
// Your views & Codes
ConstraintLayout profile = (ConstraintLayout) MyView.findViewById(R.id.ll);
ImageView imageView = (ImageView) MyView.findViewById(R.id.imageView3);
imageView.setClipToOutline(true);
SharedPreferences sharedPref = getActivity().getSharedPreferences("INFORMATION", 0);
String USERNAME = sharedPref.getString("user","");
TextView username = (TextView) MyView.findViewById(R.id.username);
Typeface custom_font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto Thin.ttf");
TextView desc = (TextView) MyView.findViewById(R.id.desc);
desc.setTypeface(custom_font);
username.setTypeface(custom_font);
username.setText(USERNAME);
new PostClass(getContext()).execute();
new PostClass_2().execute();
new PostClass_3().execute();
// Stop fragment reload [ When changing ]
} ViewGroup parent = (ViewGroup) MyView.getParent();
if (parent != null) {
parent.removeView(MyView);
}
return MyView;
}
}
如果您要设置新的ID,请使用此选项: MyView.findViewById(R.id.SetId)
希望对您有所帮助!
添加回答
举报