是否可以显示多个对话框?是否有类似Dialog Z-Level的东西?
我正在使用DialogFragment,用户可以在其中选择元素,当他确认选择时,它将保存到数据库并在服务器上发送。如果保存操作失败,我想通知用户...是否可能出现另一个对话框?而且不会清除我的第一个对话框吗?
提前致谢。
最佳答案
确实,有可能在一个对话框中显示多个对话框 fragment 。 z顺序取决于它们的创建顺序。
在下面的代码中,有一个带有所需行为的FragmentActivity示例。
public class MyActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
//...
}
public void onSave(View view) {
Intent intent = getIntent();
this.setResult(RESULT_OK, intent);
finish();
}
public void onCancel(View view) {
finish();
}
public void SelectWeekDay(View view) {
DialogFragment selectWeekDayFragment = new SelectWeekDayFragment();
selectWeekDayFragment.show(getSupportFragmentManager(), "WeekDayDialog");
}
public class SelectWeekDayFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.week_day_dialog, container, true);
Button saveButton = (Button) view.findViewById(R.id.button_save);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CheckBox checkboxMonday = (CheckBox) getDialog().findViewById(R.id.checkBox_monday);
if (!checkboxMonday.isChecked()) {
DialogFragment saveErrorFragment = new SaveErrorFragment();
saveErrorFragment.show(getSupportFragmentManager(), "SaveErrorFragment");
}
else {
SaveToDb(); //Perform actions to store on db or what you wish
dismiss();
}
}
});
Button cancelButton = (Button) view.findViewById(R.id.button_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
return view;
}
}
public class SaveErrorFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setMessage("You must select Monday").setPositiveButton("Ok", null).create();
}
}
}
关于Android:我可以一次显示多个对话框吗?是否有类似Dialog Z-Level的东西?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10282927/