Search code examples
androidandroid-layoutandroid-recyclerviewprogress-barandroid-progressbar

The Android Progress bar not showing up


This is my layout xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fragment_body"
android:fitsSystemWindows="true">

<include
    android:id="@+id/contextToolBar"
    layout="@layout/context_toolbar_layout" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/list1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/contextToolBar"
    android:scrollbarSize="5dp"
    android:scrollbarThumbVertical="@color/scrollbarColor"
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<ProgressBar
    android:id="@+id/delete_progress"
    style="@style/Widget.AppCompat.ProgressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:visibility="gone" />

It displays a grid of images in the recyclerview. I can select a bunch of images & have an option to delete them. The following is the delete logic:

public void deleteSelectedFiles(final Context context, final List<MediaModel> selectionList) {

    String confirmationMessage = getString(R.string.delete_confirm_message);

    new AlertDialog.Builder(context)
            .setTitle(getString(R.string.action_delete))
            .setMessage(confirmationMessage)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
                View progressBar = getActivity().findViewById(R.id.delete_progress);
                dialog.cancel();
                progressBar.setVisibility(View.VISIBLE);

                deleteFileList(selectionList, this.getActivity());

                progressBar.setVisibility(View.GONE);
            })
            .setNegativeButton(android.R.string.no, null).show();
}

I am expecting the progress bar to display in the foreground while the delete operation is going on. But it just doesn't show up. Any help would be highly appreciated.


Solution

  • So I had this problem before. In my case it was because I was using a Material Design Theme for the whole app, so I had to use a specific orientation and it solved my problem. You can try with

    <ProgressBar
                    android:id="@+id/progressBarReady"
                    style="@android:style/Widget.ProgressBar.Horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="3dp"
                    android:indeterminate="true"
                    android:visibility="visible"/>