安卓整蛊游戏 源码

package ytu.it.a201758501137.widgetdemo;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class DialogActivity extends AppCompatActivity {
Button zhenggubutton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);

        zhenggubutton= (Button) findViewById(R.id.zhenggubutton);
        zhenggubutton.setOnClickListener(new DialogClick());
    }
    class DialogClick implements View.OnClickListener{
        @Override
        public void onClick(View view) {
            switch (view.getId()){
                case R.id.zhenggubutton:
                    AlertDialog.Builder dlg1=new AlertDialog.Builder(DialogActivity.this);
                    dlg1.setTitle("你被整蛊了!").setMessage("你是猪吗?").setIcon(R.drawable.xiao).setPositiveButton("我是猪", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            final String []array=new String[]{"确定","确定"};
                            AlertDialog.Builder dlg2= new AlertDialog.Builder(DialogActivity.this);
                            dlg2.setTitle("你居然是猪!").setItems(array, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    final String []array1=new String[]{"YES","YES"};
                                    AlertDialog.Builder dlg3= new AlertDialog.Builder(DialogActivity.this);
                                    dlg3.setTitle("你居然真的是猪!!").setSingleChoiceItems(array1, 0, new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            final String []array2=new String[]{"吃饭","吃饭","还是吃饭","我只会吃"};
                                            final boolean[] ischecked=new boolean[]{false,false,false,false};
                                            AlertDialog.Builder dlg4= new AlertDialog.Builder(DialogActivity.this);
                                            dlg4.setTitle("作为一只猪你的爱好是什么?").setMultiChoiceItems(array2, ischecked, new DialogInterface.OnMultiChoiceClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                                                    if(ischecked[0]==true&&ischecked[1]==true&&ischecked[2]==true&&ischecked[3]==true){
                                                        View dlgview= LayoutInflater.from(DialogActivity.this).inflate(R.layout.layout_dlg,null);
                                                        AlertDialog.Builder dlg5= new AlertDialog.Builder(DialogActivity.this);
                                                        dlg5.setTitle("恭喜你已经承认你是一只猪!").setView(dlgview).show();

                                                        Button pigbutton1,pigbutton2;
                                                        pigbutton1= (Button) dlgview.findViewById(R.id.pigbutton1);
                                                        pigbutton2= (Button) dlgview.findViewById(R.id.pigbutton2);
                                                        pigbutton1.setOnClickListener(new View.OnClickListener() {
                                                            @Override
                                                            public void onClick(View view) {
                                                                Toast.makeText(DialogActivity.this,"你不服也得服!",Toast.LENGTH_SHORT).show();
                                                            }
                                                        });
                                                        pigbutton2.setOnClickListener(new View.OnClickListener() {
                                                            @Override
                                                            public void onClick(View view) {
                                                                Intent intent;
                                                                intent=new Intent(DialogActivity.this,MainActivity.class);
                                                                startActivity(intent);
                                                                Toast.makeText(DialogActivity.this,"这还差不多!",Toast.LENGTH_SHORT).show();
                                                            }
                                                        });

                                                    }

                                                }
                                            }).show();
                                        }
                                    }).show();

                                }
                            }).setCancelable(false).show();
                        }
                    }).setNegativeButton("我不是猪", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            AlertDialog.Builder dlg1=new AlertDialog.Builder(DialogActivity.this);
                            dlg1.setTitle("你被整蛊了!").setMessage("你是猪吗?").setIcon(R.drawable.xiao).setPositiveButton("我是猪", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    final String []array=new String[]{"确定","确定"};
                                    AlertDialog.Builder dlg2= new AlertDialog.Builder(DialogActivity.this);
                                    dlg2.setTitle("你居然是猪!").setItems(array, new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            final String []array1=new String[]{"YES","YES"};
                                            AlertDialog.Builder dlg3= new AlertDialog.Builder(DialogActivity.this);
                                            dlg3.setTitle("你居然真的是猪!!").setSingleChoiceItems(array1, 0, new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    final String []array2=new String[]{"吃饭","吃饭","还是吃饭","我只会吃"};
                                                    final boolean[] ischecked=new boolean[]{false,false,false,false};
                                                    AlertDialog.Builder dlg4= new AlertDialog.Builder(DialogActivity.this);
                                                    dlg4.setTitle("作为一只猪你的爱好是什么?").setMultiChoiceItems(array2, ischecked, new DialogInterface.OnMultiChoiceClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                                                            if(ischecked[0]==true&&ischecked[1]==true&&ischecked[2]==true&&ischecked[3]==true){
                                                                View dlgview= LayoutInflater.from(DialogActivity.this).inflate(R.layout.layout_dlg,null);
                                                                AlertDialog.Builder dlg5= new AlertDialog.Builder(DialogActivity.this);
                                                                dlg5.setTitle("恭喜你已经承认你是一只猪!").setView(dlgview).show();

                                                                Button pigbutton1,pigbutton2;
                                                                pigbutton1= (Button) dlgview.findViewById(R.id.pigbutton1);
                                                                pigbutton2= (Button) dlgview.findViewById(R.id.pigbutton2);
                                                                pigbutton1.setOnClickListener(new View.OnClickListener() {
                                                                    @Override
                                                                    public void onClick(View view) {
                                                                        Toast.makeText(DialogActivity.this,"你不服也得服!",Toast.LENGTH_SHORT).show();
                                                                    }
                                                                });
                                                                pigbutton2.setOnClickListener(new View.OnClickListener() {
                                                                    @Override
                                                                    public void onClick(View view) {
                                                                        Intent intent;
                                                                        intent=new Intent(DialogActivity.this,MainActivity.class);
                                                                        startActivity(intent);
                                                                        Toast.makeText(DialogActivity.this,"这还差不多!",Toast.LENGTH_SHORT).show();
                                                                    }
                                                                });

                                                            }
                                                        }
                                                    }).show();

                                                }
                                            }).show();

                                        }
                                    }).setCancelable(false).show();
                                }
                            }).setNegativeButton("我不是猪", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }).setCancelable(false).show();
                        }
                    }).setCancelable(false).show();
            }
        }
    }
}

上一篇:[NOIp 2015]斗地主


下一篇:Android学习笔记使用AlertDialog实现对话框