警告对话框中的两个按钮 [英] Alert Dialog Two Buttons

查看:119
本文介绍了警告对话框中的两个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好所有我有一个简单的问题,我有一个alertDialog,我想它显示两个按钮我已经在这里搜查,但似乎选择之前没有工作了,而且去precated。

任何人都知道这样做,你可以看到我的code以下不工作的新途径。

 按钮份额=(按钮)findViewById(R.id.btn_share);
    share.setOnClickListener(新OnClickListener(){
        公共无效的onClick(视图v){
           //调用一些其他的方法之前,我猜...
             AlertDialog alertDialog =新AlertDialog.Builder(PasswActivity.this).create(); //读取更新
             alertDialog.setTitle(Uprgade);
             alertDialog.setMessage(升级内容在这里);

             alertDialog.setButton(升级,新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface对话,诠释它){

             });
                 alertDialog.setButton(取消,新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface对话,诠释它){

             });



             alertDialog.show(); //<  - 看到这个!


    }
    });
 

解决方案

试试这个

 公共无效的ShowDialog(活动活动,弦乐标题,CharSequence的消息){
    AlertDialog.Builder建设者=新AlertDialog.Builder(活动);

    如果(标题!= NULL)builder.setTitle(职称);

    builder.setMessage(消息);
    builder.setPositiveButton(OK,NULL);
    builder.setNegativeButton(取消,NULL);
    builder.show();
}
 

Hello all i have a simple problem i have a alertDialog and i want it to show two buttons i have searched here but it seems the options before don't work anymore and are deprecated.

Anyone know the new way of doing this you can see my code below that doesn't work.

  Button share = (Button) findViewById(R.id.btn_share);
    share.setOnClickListener(new OnClickListener() {   
        public void onClick(View v) {
           // call some other methods before that I guess...
             AlertDialog alertDialog = new AlertDialog.Builder(PasswActivity.this).create(); //Read Update
             alertDialog.setTitle("Uprgade");
             alertDialog.setMessage("Upgrade Text Here");

             alertDialog.setButton("Upgrade", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

             });
                 alertDialog.setButton("Cancel", new DialogInterface.OnClickListener()    {
                public void onClick(DialogInterface dialog, int which) {

             });



             alertDialog.show();  //<-- See This!


    }
    });

解决方案

try this

public void showDialog(Activity activity, String title, CharSequence message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    if (title != null) builder.setTitle(title);

    builder.setMessage(message);
    builder.setPositiveButton("OK", null);
    builder.setNegativeButton("Cancel", null);
    builder.show();
}

这篇关于警告对话框中的两个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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