AlertDialog.Builder选择对话框

1.选择对话框:

 final String[] formatSettingItems = {"ASCII","Hexadecimal", "Decimal"};

new AlertDialog.Builder(context).setTitle("Data Format")
            .setItems(formatSettingItems, new DialogInterface.OnClickListener() 
            {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {    
                    MenuItem item = myMenu.findItem(MENU_FORMAT);
                    if(0 == which)
                    {                        
                        inputFormat = FORMAT_ASCII;
                        item.setTitle("Format - "+ formatSettingItems[0]);
                    }
                    else if(1 == which)
                    {
                        inputFormat = FORMAT_HEX;
                        item.setTitle("Format - "+ formatSettingItems[1]);
                    }
                    else
                    {
                        inputFormat = FORMAT_DEC;
                        item.setTitle("Format - "+ formatSettingItems[2]);                        
                    }
                }
            }).show();          

效果图:

选择后:

2.带确认和取消按钮的对话框:

           new AlertDialog.Builder(context)
                   .setMessage("此手机号已注册过,请直接登录或找回密码")
                   .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                       @Override
                       public void onClick(DialogInterface dialogInterface, int i) {
                           // TODO Auto-generated method stub
                           finish();
                       }
                   })
                   .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                       @Override
                       public void onClick(DialogInterface dialogInterface, int i) {
                           // TODO Auto-generated method stub
                       }
                   }).show();

效果图:

 

posted on 2016-04-11 11:24  皮皮鲁西西  阅读(684)  评论(0编辑  收藏  举报

导航