相关疑难解决方法(0)

如何使用Dialog Fragment?(showDialog已弃用)Android

我知道有这个文档

http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialog

但作为一个新的Android/Java学习者,通过编写一个弹出2个选项(是/否)消息的简单警告对话框来理解所涉及的代码量并不容易.

这是我目前在MainActivity文件中的代码:

final private int RESET_DIALOG = 0;

    private OnClickListener resetButtonListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(RESET_DIALOG);

        }
    };

    protected android.app.Dialog onCreateDialog(int id) {
        switch(id) {
        case RESET_DIALOG: 
            AlertDialog.Builder builder = new Builder(this);
            return builder
                    .setMessage("Are you sure you want to reset the count?")
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {    

                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            Toast.makeText(MainActivity.this, "Did not reset!", 5).show();

                        }
                    })

                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {


                        @Override
                        public void onClick(DialogInterface arg0, int …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-alertdialog

25
推荐指数
3
解决办法
6万
查看次数