I am trying to show an alert dialog which contains a loading animation. The Alert dialog needs to appear after clicking another alert dialog that was initially in display. Basically,the first dialog contains a setPositive and setNegative button. The setPositive event is triggers a process which takes a few seconds. I wanted the second dialog containing the loading animation to appear when the process begins. I am not able to dismiss the first dialog until the process is done for the loading dialog to show.
//dialog that contains loading animation public class LoadingBox { Activity myActivity; AlertDialog dialog; LoadingBox(Activity activity){ myActivity = activity; } void startLoadingDialog(){ AlertDialog.Builder builder = new AlertDialog.Builder(myActivity); LayoutInflater inflater = myActivity.getLayoutInflater(); builder.setView(inflater.inflate(R.layout.layout_dialog,null)); builder.setCancelable(true); dialog = builder.create(); dialog.show(); } void dismissDialog(){ dialog.dismiss(); } } new AlertDialog.Builder(SmsListActivity.this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Add To Transaction List") .setMessage("Please note that this process might take long. Proceed?") .setPositiveButton("yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LoadingBox loadingBox = new LoadingBox(SmsListActivity.this); loadingBox.startLoadingDialog(); addPendingToList(); loadingBox.dismissDialog(); } }).setNegativeButton("No",null).show();