Java android中的警报框不工作
代码不起作用。请帮帮我。它打印replaceall字符串,但没有运行进一步的代码 当我调试这个时,代码中没有错误。它将显示警报框的代码Java android中的警报框不工作,java,android,android-alertdialog,Java,Android,Android Alertdialog,代码不起作用。请帮帮我。它打印replaceall字符串,但没有运行进一步的代码 当我调试这个时,代码中没有错误。它将显示警报框的代码 if(count>0) { System.out.println("replace all string name "); // final Intent intent_ul=new Intent(this, UploadExcel.class);
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();
}
});
}
您需要添加
alertDialogBuilder_ue.show();
在您的代码中检查此代码。这个代码对我有用
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();
如果条件结束,则在结束之前添加这些行
AlertDialog alertDialog = alertDialogBuilder_ue.create();
alertDialog.show();
在代码中添加
alertDialogBuilder_ue.show()代码>应使对话框出现
一些人建议您使用alertDialogBuilder_ue.create()
获取警报对话框
的句柄,然后可以在上使用.show()
方法
这两种方法都是可能的,但是如果您不需要AlertDialog
的句柄,您就不必使用.create()
选项,您能解释一下AlertDialog AlertDialog=alertDialogBuilder_u u u u.create()吗代码>行?什么是alertDialogBuilder\u ue
alertDialogBuilder\u ue是一个生成器对象,您可以使用它创建alertdialog,您不能直接使用生成器对象来显示alertdialog。因此,您必须先获取AlerDialog的实例,然后调用它的show()。