android中的警报框无效

时间:2012-12-13 06:19:28

标签: java android alertdialog

代码无效。请帮我。它打印替换所有字符串,但进一步的代码没有运行。

当我调试它时,代码中没有错误。它将显示警告框的代码。

if(count>0)

          {
              System.out.println("replace all string name ");
                 // final Intent intent_ul=new Intent(this, UploadExcel.class);
              AlertDialog.Builder alertDialogBuilder_ue = new AlertDialog.Builder(this);            
                 alertDialogBuilder_ue.setTitle("Alert!!");
                 alertDialogBuilder_ue
                    .setMessage("Are you sure you want to Replace all the data related to this style ? ")

                    .setCancelable(false)
                    .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                             mySQLiteAdapter.openToWrite();
                              mySQLiteAdapter.delete_style_measurement(style_no);
                              Log.d("","yes click");
                              count=0;
                              mySQLiteAdapter.close();

                        }
                    })
                    .setNegativeButton("No",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            Log.d("","No click");
                            count++;
                            dialog.cancel();
                            // startActivity(intent_ul);
                             //finish();
                        }
                    });
          }

4 个答案:

答案 0 :(得分:1)

if 条件

结束之前添加这些行
 AlertDialog alertDialog = alertDialogBuilder_ue.create();
 alertDialog.show();

答案 1 :(得分:0)

您需要添加

alertDialogBuilder_ue.show();

代码

答案 2 :(得分:0)

检查此代码。这段代码为我工作

Context context = CurrentActivity.this;
AlertDialog.Builder ad = new AlertDialog.Builder(context);
ad.setTitle("Application");
ad.setMessage("Do you want to proceed?");
ad.setPositiveButton("Yes", new OnClickListener() 
{
 public void onClick(DialogInterface dialog, int arg1) 
 {

 }
});
ad.setNegativeButton("Cancel", new OnClickListener() 
{
 public void onClick(DialogInterface dialog, int arg1)
 {

 }
});
ad.setCancelable(false);
ad.show();

答案 3 :(得分:0)

在您的代码中添加alertDialogBuilder_ue.show();应该会显示对话框。

有些人建议您 使用alertDialogBuilder_ue.create();来获取AlertDialog的句柄,然后您可以使用.show()方法上。

如果你不需要.create()

的句柄,那么这两种可能性都是没有来使用AlertDialog选项