Adi
Adi

Reputation: 361

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.

Upvotes: 1

Views: 9205

Answers (3)

Tayyab Mazhar
Tayyab Mazhar

Reputation: 1702

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

style="?android:attr/progressBarStyle" is what fixed it for me.

Upvotes: 0

wat er
wat er

Reputation: 471

I had a similar problem. In my case, I was using a ProgressBar as a loading indicator inside a CoordinatorLayout. In the Activity/Fragment - at different points - based on the data becoming available - ie using a Cursor or from the Network, I needed to call mViewA.setVisibility(View.GONE) or mViewB.setVisibility(View.VISIBLE). When I set these up correctly for my views including the ProgressBar View, it became visible.

Upvotes: 1

Hermes
Hermes

Reputation: 467

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"/>

Upvotes: 11

Related Questions