gpt4 book ai didi

java - 当 fragment 处于​​恢复状态时,如果条件为真,它将返回到创建 View

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:49 25 4
gpt4 key购买 nike

如果满足特定条件,我希望恢复阶段的 fragment 返回到创建 View 阶段,这可能吗?

 public class FragBeamRec extends Fragment {

public static FragBeamRec newInstance() {
FragBeamRec fragment = new FragBeamRec();
return fragment;
}

public FragBeamRec() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_frag2, container, false);

globalvar.booIstrue = false;

return inflater.inflate(R.layout.fragment_frag2, container, false);
}

@Override
public void onResume(){
super.onResume();

if (globalvar.booIstrue){
// what do i write here to make it back to onCreateView
}
}
}

最佳答案

只需将 onCreateView 逻辑移至单独的方法中即可。这就是窍门。干杯:)

public class FragBeamRec extends Fragment {

public static FragBeamRec newInstance() {
FragBeamRec fragment = new FragBeamRec();
return fragment;
}

public FragBeamRec() {}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_frag2, container, false);


doYourMagicHere();

return inflater.inflate(R.layout.fragment_frag2, container, false);
}

@Override
public void onResume() {
super.onResume();


if (globalvar.booIstrue) {
// what do i write here to make it back to onCreateView
doYourMagicHere();
}
}
public void doYourMagicHere() {
globalvar.booIstrue = false;
}
}

关于java - 当 fragment 处于​​恢复状态时,如果条件为真,它将返回到创建 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36137126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com