每次单击如何停止片段重新加载?

我有一个底部导航,它负责切换片段。

因此,每当我单击按钮两次时,片段每次都会在其上重新加载内容。

如何停止该片段 ?我只想向上滚动即可重新加载页面


public View onCreateView(LayoutInflater inflater, ViewGroup container,

                         Bundle savedInstanceState) {

    // Inflate the layout for this fragment

    View Layout = inflater.inflate(R.layout.fragment_profile, container, false);

    ConstraintLayout profile = (ConstraintLayout) Layout.findViewById(R.id.ll);

    ImageView imageView = (ImageView) Layout.findViewById(R.id.imageView3);

    imageView.setClipToOutline(true);

    SharedPreferences sharedPref = getActivity().getSharedPreferences("INFORMATION", 0);

    String USERNAME = sharedPref.getString("user","");

    TextView username = (TextView) Layout.findViewById(R.id.username);

    Typeface custom_font = Typeface.createFromAsset(getActivity().getAssets(),  "fonts/Roboto Thin.ttf");

    TextView desc = (TextView) Layout.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();

    return Layout;

每次更改片段时,都会执行以上代码。我想通过像片段中的chrome一样向上滚动来重新加载它。任何帮助表示赞赏


米脂
浏览 168回答 1
1回答

偶然的你

我很久以前就遇到过这个问题:/但我找到了解决问题的简单方法:)用这个来解决问题:// 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)希望对您有所帮助!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java