0

我在 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();这个 onPostExecute 代码

           else {
                    tvStatus.setText("Sending Data : Finished");
                    CUtilities.showAlert(CInputHamaApp.this, "Data Terkirim");
                    createDialogSend2();
                    // Closing dashboard screen
                }

但结果是当状态完成时,对话框仅显示警报,而createDialogSend2();不是运行。

如何createDialogSend2()在文本发送数据完成时显示

BR

亚历克斯

4

3 回答 3

3

您的功能没有show()对话框。你需要类似...

AlertDialog dlg = createDialogSend2();
dlg.show();
于 2013-02-01T18:55:36.097 回答
0

试试这个,

AlertDialog alert = builder.create();    
alert.show();

将此添加到您的createDialogSend2()

于 2013-02-01T18:56:59.190 回答
0

这对我有用,在 OnPostExecute 方法中。

我在我的 AsyncTask 类中添加 Activity 对象作为属性,我在该 AsyncTack 的构造函数中实例化它,以便我可以调用该活动并在 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();
                }
            });
于 2013-03-20T02:34:12.433 回答