Reputation: 128
Unable to see custom progress dialog on dialog fragment
Custom progress dialog works in Activity and Fragment but when we try to show custom progress in Dialog Fragment then loader is not showing.
Here is my code of custom dialog.
/**
* A simple {@link Fragment} subclass.
*/
public class CustomAlertDialogFragment extends Dialog {
/**
* Instantiates a new Custom alert dialog fragment.
*
* @param context the context
* @param text the text
*/
public CustomAlertDialogFragment(Context context, String text) {
super(context, android.R.style.Theme_Holo_Dialog_NoActionBar);
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ProgressBar v = new ProgressBar(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(v);
setCancelable(false);
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
}
}
And my code for showing loader is
/**
* Loading bar.
*
* @param enable the enable
*/
public void loadingBar(boolean enable) {
if (enable) {
if (progressDialog == null) {
progressDialog = new CustomAlertDialogFragment(getActivity(), "");
}
if (!progressDialog.isShowing())
progressDialog.show();
} else {
dismissProgressBar();
}
}
/**
* Dismiss progress bar.
*/
public void dismissProgressBar() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
I am calling loader as
loadingBar(true);
File source = new File("/mnt/extSdCard/Audio");
File dest = new File("/mnt/UsbDriveA/Dokita");
copyDirectory(source, dest);
loadingBar(false);
Upvotes: 3
Views: 703
Reputation: 812
Maybe you are running long running tasks(which should be done in background) in a Thread or with an AsyncTask
Implement the code below in your app
Thread thread = new Thread() {
@Override
public void run() {
loadingBar(true);
File source = new File("/mnt/extSdCard/Audio"); // source of file
File dest = new File("/mnt/UsbDriveA/Dokita"); // destination of file
copyDirectory(source, dest);
loadingBar(false);
}
};
copyDirectory(source, dest);
thread.start();
Upvotes: 3