警告对话框中的两个按钮按钮、两个、对话框中

2023-09-05 07:13:17 作者:淚、落在琴弦上

您好所有我有一个简单的问题,我有一个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();
}