从另一个DialogFragment显示DialogFragment [英] Show DialogFragment from another DialogFragment
问题描述
我有一个DialogFragment
,向用户显示选项列表,这些选项之一是删除"选项,当用户按下Delete选项时,我想显示另一个DialogFragment作为确认,不幸的是,该确认对话框不显示.
I have a DialogFragment
that displays a list of options to the user, one of these options is "Delete" option, when the user presses the delete option I want to show another DialogFragment as a confirmation, unfortunately, the confirmation dialog doesn't show.
这是我的代码
第一个片段代码
public class ContactDialogOption extends SherlockDialogFragment {
public static final String TAG = ContactDialogOption.class.getSimpleName();
public ContactDialogOption() {
super();
// TODO Auto-generated constructor stub
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(R.string.options);
builder.setItems(new String[] {
getString(R.string.call), getString(R.string.send_message),
getString(R.string.copy), getString(R.string.edit),
getString(R.string.delete)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(which == 4) //delete
{
FragmentManager mgr = getActivity().getSupportFragmentManager();
FragmentTransaction ft = mgr.beginTransaction();
Fragment old = mgr.findFragmentByTag("SecondFragment");
if (old != null) {
ft.remove(old);
}
ft.addToBackStack(null);
fragment.show(ft, fragmentTag);
}
}
});
return builder.create();
}
}
推荐答案
我遇到了完全相同的问题,当您尝试从Fragment
打开DialogFragment
时,不会发生这种情况.
I got the exact same problem, this situation does not happen when you try to open a DialogFragment
from a Fragment
.
我发现的唯一解决方案是修改以下调用:
The only solution I found was to modify the following call:
fragment.show(ft, fragmentTag);
收件人:
fragment.show(getFragmentManager(), fragmentTag);
此解决方案的问题在于我们无法在FragmentTransition
上工作.
The problem with this solution is that we cannot work on the FragmentTransition
.
我不明白为什么行为与片段不同.
I don't understand why the behavior is different than with the fragments.
这篇关于从另一个DialogFragment显示DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!