2012-02-07 38 views
0
public class IdAsync extends AsyncTask<String, Void, Void> { 

AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); 

    protected Void doInBackground(String... params) { 
     . 
     . 
     alertDialog.setTitle("Reset..."); 
      alertDialog.setMessage("R u sure?"); 
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 

        //here you can add functions 

       } }); 

    alertDialog.show(); 
     . 
    .} 

这给出了运行时错误 发生错误E/AndroidRuntime(16606):在android.app.Dialog.show(Dialog.java:241)AlertBox - 执行doInBackground()

回答

1

您应该在AsyncTask的onPostExecute,onPreExecute或onProgressUpdate方法中执行对话框来更新UI。 不在背后。

相关问题