Android 在onPostExecute Asynctask中运行对话框
我在Asynctask中有onPostExecuteAndroid 在onPostExecute Asynctask中运行对话框,android,Android,我在Asynctask中有onPostExecute protected void onPostExecute(Void unused) { TextView tvStatus=(TextView) layoutSendDialog.findViewById(R.id.tvPupukSendStatus); if (bNodata){ tvStatus.setText("No data to be sent!!!");
protected void onPostExecute(Void unused) {
TextView tvStatus=(TextView) layoutSendDialog.findViewById(R.id.tvPupukSendStatus);
if (bNodata){
tvStatus.setText("No data to be sent!!!");
}else {
if (bError){
tvStatus.setText("Fail at record #"+String.format("%d",recordCount));
}
else {
tvStatus.setText("Sending Data : Finished");
CUtilities.showAlert(CInputHamaApp.this, "Data Terkirim");
createDialogSend2();
// Closing dashboard screen
}
}
// dismissDialog(CGeneral.DIALOG_SEND);
}
这是我的对话
private Dialog createDialogSend2(){
AlertDialog.Builder builder = new AlertDialog.Builder(CInputHamaApp.this);
builder.setMessage("Anda yakin untuk update?");
builder.setTitle("Warning") ;
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Intent i2 = new Intent(CInputHamaApp.this, CInputHamaApp.class);
startActivity(i2);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
// do nothing – it will close on its own
}
});
return builder.create();
}//createDialogSend2
我把createDialogSend2()此onPostExecute代码中的代码>
else {
tvStatus.setText("Sending Data : Finished");
CUtilities.showAlert(CInputHamaApp.this, "Data Terkirim");
createDialogSend2();
// Closing dashboard screen
}
但结果是当状态完成时,对话框仅显示警报,并且createDialogSend2()代码>未运行
文本发送数据完成时如何显示createDialogSend2()
溴
Alex您的函数不显示()对话框。你需要像
AlertDialog dlg = createDialogSend2();
dlg.show();
您的函数不show()
对话框。你需要像
AlertDialog dlg = createDialogSend2();
dlg.show();
试试这个
AlertDialog alert = builder.create();
alert.show();
将此添加到您的createDialogSend2()
尝试此操作
AlertDialog alert = builder.create();
alert.show();
将此添加到您的createDialogSend2()
在OnPostExecute方法中,这对我很有用
我将Activity对象作为propretie添加到AsyncTask类中,我在该AsyncTack的构造函数中实例化该类,以便调用该Activity并在onpostexe中执行runOnUiThread
AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
builder.setTitle("Connection ?");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage("Test \n ");
builder.setPositiveButton("Ok",null);
final AlertDialog alert = builder.create();
Activity.runOnUiThread(new java.lang.Runnable(){
public void run(){
//show AlertDialog
alert.show();
}
});
在OnPostExecute方法中,这对我很有用
我将Activity对象作为propretie添加到AsyncTask类中,我在该AsyncTack的构造函数中实例化该类,以便调用该Activity并在onpostexe中执行runOnUiThread
AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
builder.setTitle("Connection ?");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage("Test \n ");
builder.setPositiveButton("Ok",null);
final AlertDialog alert = builder.create();
Activity.runOnUiThread(new java.lang.Runnable(){
public void run(){
//show AlertDialog
alert.show();
}
});
当我在eclipse中尝试错误时,类型不匹配:无法从Dialog转换为AlertDialog
@David M当我在eclipse中尝试错误时,函数的返回类型应为AlertDialog
而不是Dialog
类型不匹配:无法从Dialog转换为AlertDialog
@David M函数的返回类型应为AlertDialog
notDialog
我尝试将代码放入createDialogSend2()禁用是,但对话框不显示。我尝试将代码放入createDialogSend2()禁用是,但对话框不显示。