Android 在DialogFragment解除后重新加载片段

Android 在DialogFragment解除后重新加载片段,android,android-fragments,Android,Android Fragments,我将Index.class作为活动,当用户选择Profile时,它将调用fragment Profile if (id == R.id.nav_profile){ FragmentTransaction transaction = getSupportFragmentManager() .beginTransaction(); transaction.setCustomAnimations(R.anim.enter,R.anim

我将Index.class作为活动,当用户选择Profile时,它将调用fragment Profile

  if (id == R.id.nav_profile){
        FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();
        transaction.setCustomAnimations(R.anim.enter,R.anim.exit,R.anim.enter,R.anim.exit);
        transaction.replace(R.id.flContent, new Profile(), "ProfileFragment");
        transaction.addToBackStack(null);
        viewPager.getAdapter().notifyDataSetChanged();
        transaction.commit();
    }
现在在Profile片段中,当用户单击一个按钮时,它将调用DevRegistration活动

 case 1:
            btnBeDeveloper.setText("Developer Console");
            btnBeDeveloper.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                     Intent index = new Intent(getActivity(), DevRegistration.class);
                    startActivity(index);
                }
            });
            break;
然后在DevRegistration类中,单击register按钮后,它将显示一个对话框片段类。 我想做的是,当我单击对话框片段内的按钮时,如何刷新概要文件片段

对话框片段类:

public class df_SuccessDevRegistration extends DialogFragment {

Button btnDevGoProfile;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    View rootView = inflater.inflate(R.layout.fragment_success_developer_registration, container, false);

    btnDevGoProfile = (Button) rootView.findViewById(R.id.btnDevGoProfile);

    btnDevGoProfile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
            getFragmentManager().popBackStack();
            getActivity().finish();

            Profile fragment = (Profile)
                    getSupportFragmentManager().findFragmentByTag("ProfileFragment");

            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction()
            transaction.detach(fragment);
            transaction.attach(fragment);
            transaction.commit();

        }
    });

    return rootView;
}
}


顺便说一下,我不知道为什么getSupportFragmentManager不工作。它显示无法解析方法的错误。。。当我使用getFragmentManager()时,它会崩溃。

在您的开发人员注册活动中,获取您的片段:

Profile profileFragment = getSupportFragmentManager().findFragmentByTag("ProfileFragment");
要刷新它,您可以尝试:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.detach(profileFragment);
transaction.attach(profileFragment);
transaction.commit();
编辑:

你能试试这个吗

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    View rootView = inflater.inflate(R.layout.fragment_success_developer_registration, container, false);

    btnDevGoProfile = (Button) rootView.findViewById(R.id.btnDevGoProfile);



    return rootView;
}

@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        btnDevGoProfile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().getSupportFragmentManager().popBackStack();


            Profile fragment = (Profile)
                    getActivity().getSupportFragmentManager().findFragmentByTag("ProfileFragment");

            FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction()
            transaction.detach(fragment);
            transaction.attach(fragment);
            transaction.commit();

            getActivity().finish();
            dismiss();

        }
    });
    }

希望这能有所帮助。

您也可以尝试刷新当前片段

 FragmentTransaction ftran = getActivity().getFragmentManager().beginTransaction();
 ftran .detach(this).attach(this).commit();

使用自定义侦听器接口您可以共享您的对话片段类吗?我应该将代码放在DevRegistration活动中还是放在我的对话片段中?单击对话框片段内的按钮后,我需要刷新代码。对话框片段在您的DevRegistration活动中,对吗?它是dialogfragment类,是另一个类。在最终活动活动中,我收到错误,不兼容类型:必需:找到活动:v4.support.fragmenttry最终DevRegistration活动=(DevRegistration)getActivity();我的片段在[java->packageName->Fragments]文件夹中,无法使用.detach(这个)。请帮忙