Android Multiple Nested DialogFragment

Android Multiple Nested DialogFragment,第1张

概述我有一个场景,我显示一个DialogFragment(使用getSupportFragmentManager()),显示一个值列表和一个“添加”按钮.如果用户单击添加按钮,我会显示另一个DialogFragment(使用由EditText和Button组成的getChildFragmentManager().当用户点击新Button时,如果值通过验证,我将其添加到列表中.如果不是通过验证,我显示另 我有一个场景,我显示一个DialogFragment(使用getSupportFragmentManager()),显示一个值列表和一个“添加”按钮.如果用户单击添加按钮,我会显示另一个DialogFragment(使用由EditText和button组成的getChildFragmentManager().当用户点击新button时,如果值通过验证,我将其添加到列表中.如果不是通过验证,我显示另一个显示错误消息的DialogFragment和一个“确定”按钮.我希望当按下“确定”按钮时,用户仍然会看到带有EditText和button的DialogFragment,这样他们就可以查看错误值并可能更改它.但是,当在错误消息DialogFragment中按下“确定”按钮时,对话框将被关闭,并且仅显示原始DialogFragment(具有值列表的那个).

在第三个DialogFragment被解散后,我如何保持第二个DialogFragment仍然显示?

编辑:这是一些代码片段:

//clicking this button shows the first ("outer") fragmentfindVIEwByID(R.ID.voicemail_notifications_email_addresses).setonClickListener(new OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            AddressListDialog.newInstance(                    line,AddressListDialog.VOICEMAIL_NOTIFICATIONS_EMAIL)                  .show(((FragmentActivity)getContext()).getSupportFragmentManager(),"dialog");        }});public static class AddressListDialog extends DialogFragment {    public AddressListDialog() {}    @OverrIDe    public Dialog onCreateDialog(Bundle savedInstanceState) {        final VIEw v = LayoutInflater.from(getActivity()).inflate(R.layout.vm_address_List_dialog,null);        ListVIEw lv = (ListVIEw) v.findVIEwByID(R.ID.voicemail_notifications_address_List);        final AddressAdapter adapter = new AddressAdapter();        lv.setAdapter(adapter);        v.findVIEwByID(R.ID.voicemail_add_address_button).setonClickListener(new OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                //first child fragment                AddAddressDialog.newInstance(getType()).setAdapter(adapter)                                .show(getChildFragmentManager(),"dialog");            }        });        Dialog d = new AlertDialog.Builder(getActivity())                .setTitle(TitleRes)                .setVIEw(v)                .setPositivebutton(R.string.global_dialog_pos,new DialogInterface.OnClickListener() {                        public voID onClick(DialogInterface dialog,int whichbutton) {                            dialog.dismiss();                        }                    }                )                .create();        return d;    }    private class AddressAdapter extends BaseAdapter {        .        .        .        public boolean add(lineVoicemailinfo.VmContact contact) {            if(addresses.size() >= 3) {                return false;            }            else if(!contact.isValID(isEmailType())) {                return true;            }            else {                addresses.add(contact);                notifyDataSetChanged();                return true;            }        }public static class AddAddressDialog extends DialogFragment {    private AddressAdapter adapter;    public AddAddressDialog() {}    @OverrIDe    public Dialog onCreateDialog(Bundle savedInstanceState) {        DialogInterface.OnClickListener onPosClick = null;        final VIEw v;        v = LayoutInflater.from(getActivity()).inflate(R.layout.voicemail_add_email_address,null);        onPosClick = new DialogInterface.OnClickListener() {                                    @OverrIDe            public voID onClick(DialogInterface dialog,int which) {                lineVoicemailinfo.VmContact contact = new lineVoicemailinfo.VmContact(((EditText)v.findVIEwByID(R.ID.voicemail_add_email_address)).getText().toString());                if(!adapter.add(contact)) {                    //second child fragment                    BadAddressDialog.newInstance("Not a valID address")                                    .show(getChildFragmentManager(),"dialog");                }            }        };        Dialog d = new AlertDialog.Builder(getActivity())                .setTitle("Add Address")                .setVIEw(v)                .setCancelable(false)                .setPositivebutton(R.string.voicemail_addresses_add,onPosClick)                .setNegativebutton(R.string.global_dialog_neg,int whichbutton) {                           dialog.dismiss();                        }                })                .create();        setCancelable(false);        return d;    }}public static class BadAddressDialog extends DialogFragment {                   public BadAddressDialog() {}        public static BadAddressDialog newInstance(String message) {            BadAddressDialog frag = new BadAddressDialog();            Bundle args = new Bundle();            args.putString("message",message);            frag.setArguments(args);            return frag;        }        @OverrIDe        public Dialog onCreateDialog(Bundle savedInstanceState) {               String message = getArguments().getString("message");            Dialog d = new AlertDialog.Builder(getActivity())                    .setTitle("Error adding address")                    .setMessage(message)                    .setCancelable(false)                    .setPositivebutton(R.string.global_dialog_pos,int whichbutton) {                            dialog.dismiss();                        }                    })                    .create();            setCancelable(false);            return d;        }    }
解决方法 我想问题是你使用标准的show方法来显示对话框.根据AndroID的消息来源,这个方法不会向backstack添加片段,所以最顶层的对话框被解雇,中间也被解雇了.

您应该在调用show之前自己开始trasaction并将事务添加到backstack(调用addToBackStack).一个例子显示在DialogFragment documentation page上.

总结

以上是内存溢出为你收集整理的Android Multiple Nested DialogFragment全部内容,希望文章能够帮你解决Android Multiple Nested DialogFragment所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1129360.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存