Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在onPostExecute Asynctask中运行对话框_Android - Fatal编程技术网

Android 在onPostExecute Asynctask中运行对话框

Android 在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!!!");

我在Asynctask中有onPostExecute

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()

           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
not
Dialog
我尝试将代码放入createDialogSend2()禁用是,但对话框不显示。我尝试将代码放入createDialogSend2()禁用是,但对话框不显示。