I have a progress dialog in my every activity and in every activity I write code for progress dialog with different message where I want.Is there any way to put progress dialog code in seperate class and call that class in activity where I want to show that progress dialog.
here is my code for progress dialog:-
ProgressDialog m_Dialog = new ProgressDialog(CLoginScreen.this);
m_Dialog.setMessage("Please wait while logging...");
m_Dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
m_Dialog.setCancelable(false);
m_Dialog.show();
You can define a class
to encapsulate this operation and maybe some other involving dialogs. I use a class
with static
methods, something like this:
public class DialogsUtils {
public static ProgressDialog showProgressDialog(Context context, String message){
ProgressDialog m_Dialog = new ProgressDialog(context);
m_Dialog.setMessage(message);
m_Dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
m_Dialog.setCancelable(false);
m_Dialog.show();
return m_Dialog;
}
}
In the Activity class:
ProgressDialog myDialog= DialogUtils.showProgressDialog(this,"some message");
...
myDialog.dismiss();
Of course you can add others parameters to the operation so it can be more flexible.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With