如何更改对话框片段中的片段 [英] how to change fragment inside a dialogfragment

查看:62
本文介绍了如何更改对话框片段中的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 LinearLayout 创建一个空的 DialogFragment ,然后更改 LinearLayout 内部的片段.例如,一个登录名的第一个片段是3按钮(facebook,google +,电子邮件登录),而当有人按下电子邮件时,则2.片段的布局为 EditTexts (如果按下了Google或Facebook,则该其他片段显示为 ProgressBar .

I want to make an empty DialogFragment with a LinearLayout and then change fragments inside the LinearLayout. For example, a login where the first fragment is 3 button (facebook, google+, email login) and when somebody pressed email then the 2. fragment has a layout with EditTexts if Google or Facebook was pressed then the other fragment appears with a ProgressBar.

这是我的空白对话框布局:

this is my empty dialog layout:

<?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>

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

And this is the first fragment's code (I am using android annotations):

@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());

    }


}

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;
    }

推荐答案

您需要从对话框片段

You need to get the childFragmentManager from the dialogfragment link, then from the child fragments you can change the fragments via getParentFragment().getChildFragmentManager()

这篇关于如何更改对话框片段中的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆