Android:我可以一个接一个地显示多个对话框吗?有没有像Dialog Z-Level这样的东西? [英] Android: Can i show multiple Dialogs one over another? Is there something like Dialog Z-Level?

查看:48
本文介绍了Android:我可以一个接一个地显示多个对话框吗?有没有像Dialog Z-Level这样的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以一个接一个地显示多个对话框?有没有像Dialog Z-Level这样的东西?我正在使用 DialogFragment 用户选择元素,当他确认他的选择时,它被保存到数据库并发送到服务器上.如果保存操作失败,我想通知用户......是否可以使用另一个对话框?它不会清除我的第一个对话吗?提前致谢.

Is it possible to show multiple Dialogs one over another? Is there something like Dialog Z-Level? I am using DialogFragment where user chooses elements, when he comfirms his choice, it is saved to database and sent on server. if the save action fails I would like to inform user with ... another dialog is it possible? And will it not clear off my first dialog? Thanks in advance.

推荐答案

确实,可以在另一个内显示多个对话框片段.z 顺序取决于它们的创建顺序.

Indeed, it's possible to show multiple dialog Fragments one inside another one. The z-order depends on the order they are created.

在下面的代码中有一个 FragmentActivity 的例子,它具有您需要的行为.

In the code below there is an example of a FragmentActivity with the behavior that you require.

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这样的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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