2

I'm trying to use ContentLoadingProgressBar to display 1 second before hiding itself. However I can't seem to find any examples of how to use it correctly with a recyclerview.

So I've tried using just testing it, but I can't get it to display for a minimum amount of time. How would I do so?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.core.widget.ContentLoadingProgressBar
        android:id="@+id/main_progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        style="?android:attr/progressBarStyleLarge"
        android:visibility="visible"/>

</RelativeLayout>

I've simply just tried doing it like this:

mProgressBar.show();
mProgressBar.hide();

However it's not displaying for 1 second before hiding. It just hides automatically.

DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83

3 Answers3

0
mProgressBar.show();
Handler().postDelayed({
  mProgressBar.hide();
}, 1000)
Rasel
  • 5,488
  • 3
  • 30
  • 39
  • I thought ```ContentLoadingProgressBar``` has a built in mechanism where I don't have to do this. https://stackoverflow.com/a/41628855/11110509 – DIRTY DAVE Feb 18 '20 at 06:13
0

ContentLoadingProgressBar has minimum threshold time 500ms, so you should wait this time before hiding

Vladimir Berezkin
  • 3,580
  • 4
  • 27
  • 33
  • So do I have to manually use timer to wait? That defeats the whole point of using it then since I can do the samething with a regular progressbar – DIRTY DAVE Feb 18 '20 at 06:18
  • 1
    It looks that here is some misunderstanding. The main point of ContentLoadingProgressBar is that it is not showing if your background task is less than 500 ms. And if your task is more than 500 ms, than it will be showing at least 500 ms. All these thresholds are made to avoid blinking. – Vladimir Berezkin Feb 18 '20 at 07:32
0

ContentLoadinProgressBar is built to prevent flickering of UI during frequent show hide calls of progressBar. So if you quickly call hide(); after calling show(); then it'll ignore the show();. which is normal. to prevent flickering.

Have a look at Charuක's Answer

Harsh Jatinder
  • 833
  • 9
  • 15
  • Yeah I saw that answer, but do I still have to call ```Handler().postDelayed()``` like in the answer below? – DIRTY DAVE Feb 18 '20 at 06:24
  • Yes, but i don't think any practicle use to display any progress if you're calling `hide();` immediately after calling `show();`. because processor won't take a blink to execute them, but still if you still need that **1** progress for some reason than `Handler().postDelayed()` will help. – Harsh Jatinder Feb 18 '20 at 06:30