如何在dialogfragment中更改片段

Meg*_*gaX 3 android android-fragments

我想DialogFragment用a 做空,LinearLayout然后在里面更改片段LinearLayout.例如,登录时第一个片段是3个按钮(Facebook,谷歌+,电子邮件登录),当有人按下电子邮件时,2.片段有一个布局,EditTexts如果谷歌或Facebook被按下,那么另一个片段出现一个ProgressBar.

这是我的空对话框布局:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@drawable/dialog_background">

    <LinearLayout
        android:id="@+id/testFragmentController"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_margin="15dp"></LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是第一个片段的代码(我正在使用android注释):

@EFragment(R.layout.dialog)
public class FragmentGeneralDialog extends ClickDialogFragment {

    @ViewById
    LinearLayout testFragmentController;


    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        this.setStyle(R.style.Dialog_No_Border, getTheme());

        return dialog;
    }


    @AfterViews
    void afterViews() {
        loadActivity();
        GlobalData.setFragmentContainer(testFragmentController);
        activity.loadMenuFragment(FragmentSocialDialog_.class, new SlideLeftAnimation());

    }


}
Run Code Online (Sandbox Code Playgroud)

loadMenuFragments(...) 这是:

public <T extends Fragment> T loadMenuFragment(final Class<T> cls,
                                                   final IAnimation a) {
        T fragment = null;
        try {
            fragment = cls.newInstance();
        } catch (Exception ex) {
            throw new RuntimeException("Fragment " + cls.toString()
                    + " has no empty constructor");
        }
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        if (a != null) {
            transaction.setCustomAnimations(a.getInId(), a.getOutId(), a.getInId(),
                    a.getOutId());
        }

        transaction.replace(R.id.testFragmentController, fragment);

        try {
            transaction.commit();
        } catch (Exception e) {
        }
        return fragment;
    }
Run Code Online (Sandbox Code Playgroud)

Rot*_*ens 6

您需要childFragmentManager从dialogfragment 链接获取,然后从子片段中获取片段getParentFragment().getChildFragmentManager()