在第三个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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)