1

I have a View with multiple progress bars.Individual progress bars doesnt persist their value when i switch to last tab(tab 4) and i come back.[Basically when home tab is not visible and brought to visibility again].

The progress bars are placed inside a LinearLayout which is hosted inside Fragment. Looks like Youtube app. In home page, i have 5 progress bar. For the first time when i set progress all progress bar values looks perfect. Individual progress bar are showing their own individual values.

However when i switch to tab 4(not in picture), i come back, all progress bar's value get set to the last progress bar's value. See Image below.

Multiple Progress bar screen

I checked by removing Progress bar with TextBox, the value persists as per set. I have added max value to progress bar, used the methods 1. setProgress, 2. incrementProgressBy, no improvement.

Since textbox behaves correctly ,i couldnt figure out my problem kindly help.

PS: In android Fragment(tab) gets recreated when its not visible and brought to visibility.to avoid this i made restrictions in onCreateview to persist the last created rootview.

  • 1
    I believe you re using the word persists wrong in this context. Anyway, this may help http://stackoverflow.com/questions/15313598/once-for-all-how-to-correctly-save-instance-state-of-fragments-in-back-stack – Marcin D Jun 23 '15 at 20:53
  • I need to try this but only progress bar(only in case of multiple progress bar) shows up the last created progressbar's value. but text boxes shows their texts properly. Many thanks for directing to the above post – Vishwaram Sankaran Jun 23 '15 at 21:06

3 Answers3

2

You probably have solved this by now, but in case anyone else gets to this page with the same issue: I had the same problem, multiple progressbars in fragments in a tabbed container view (ViewPager), and all of them showing the same progress value (the one last set) after switching between tabs. I solved it by setting the progress value in the fragment's onResume instead of onCreateView.

SirMarino
  • 526
  • 3
  • 8
2

I had the same problem with 2 progressBars inside a ViewPager and fixed by using a unique drawable instance for each progressBar:

This shows wrong values on progressBar:

val progressDrawable = ContextCompat.getDrawable(it, R.drawable.progress_bar_colors)

mBinding.firstProgressBar.progressDrawable = progressDrawable
mBinding.secondProgressBar.progressDrawable = progressDrawable

And this fixed the problem:

mBinding.firstProgressBar.progressDrawable = ContextCompat.getDrawable(it, R.drawable.progress_bar_colors)
mBinding.secondProgressBar.progressDrawable = ContextCompat.getDrawable(it, R.drawable.progress_bar_colors)

I hope it helps you

Isquierdo
  • 745
  • 1
  • 10
  • 29
-1

There is an accepted answer, but I ran into this same issue with multiple progress bars on different Fragments and in recycler views. My issue was related to a well observed Android progress bar bug that does not always update progress bars (see accepted answer here: android progressBar does not update progress view/drawable)

In my case I had a custom Progress Bar and added these methods to get around this bug. Sucks that we as developers have to figure this out the hard way so often.

  fun setProgressSafely(progress: Int) {
    setProgress(progress + 1)
    setProgress(progress)
}

fun setMaxSafely(max: Int) {
    setMax(max + 1)
    setMax(max)
}
M. Smith
  • 379
  • 1
  • 20