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.
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.
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.
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
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)
}
Related
I have seen a few people trying to get an indeterminate progress bar to show and that is kind of the opposite problem than I am having.
What I want is when the app starts to do work the user sees an indeterminate progress bar at the top of the Window. Then goes away when the work is complete.
I am using the app compat v7 library. My Activity extends android.support.v7.app.ActionBarActivity.
The code I have in my Activity.onCreate() is:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
...
}
Then when work starts (in a Fragment, not on the main thread):
((ActionBarActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true);
Then when work completes:
((ActionBarActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(false);
Two curious behaviors I can't really explain. First, on setSupportProgressBarIndeterminateVisibility(true) Both the Window progress shows (that I want) and the Action Bar's circular progress bar shows.
Second, on setSupportProgressBarIndeterminateVisibility(false) the Window progress hides (hurray) and that's it... the circular progress bar stays visible...
So I don't know why any of the Action Bar's progress stuff happens, nor do I know how to make it stop. If I knew the id of the progress view in the Action Bar I could look that up in the menu and make sure it stays hidden, but I don't know that id (also seems like the wrong way to go about that).
Any help explaining this behavior would be great. Thank you!!
For the first issue:
It's not obvious from the code given, but the calls to setSupportProgressBarIndeterminateVisibility were being called from a background thread. If I move that code to the UI Thread, everything works without UI glitches.
For the second issue:
It does seem that the default behavior should be to show the circular progress bar on the ActionBar. Not entirely sure why the progress on the top of the activity shows as well. You can hide the ActionBar's progress with a style, but I moved away from that before I tested it on older Android platforms.
I have scenario where I have to show some level using a progress bar, but according to the design this progress bar has a thumb like circle on it too.
Now the user is not supposed to change the value of this bar either by touch or by using keys.
The 'thumb' is available in Seek bar but not in Progress bar, but Seek bar is capable of taking focus and touch events, while this should not happen in my case.
So for handling the focus and make my seek bar "foussable = false" & "focussableInTouchMode = false", but what should I do to make it non-touchable almost like a progress bar ?
Another option is to call setOnTouchListener and use a listener that always returns false. Note that this UI is confusing to users as you want the seekbar to look like an active one, but not behave like an active seekbar. For UI consistency, using setEnabled(false) is more consistent, and the colors are different for a good reason.
what you can do is, create custom seekbarwith following two property, and call enable(false)
android:progressDrawable="#drawable/progress_bar"
android:thumb="#android:color/transparent" // to make thumb invisible
and then call for runtime
SeekBar.setEnabled(false)
and from xml
android:enabled="false"
I have two tabs in my app.First tab displays the details of user and the second tab displays the applications that are installed on his device.I have used Package manager for getting the installed apps and it is running ins background thread. If the user clicked the second tab before the background thread completes I want to show a progressdialog.But the problem is if progressdialog is displayed on the screen user can't switch to next tab.Is there any way to solve this issue.Thanks in advance.
Progress dialogue by default works in dialogue mode and freezes any operations until the progress bar is gone.
I had faced issues with controlling progress bar (though my requirements were more than yours like customizing looks and showing/ hiding/ freezing bar at will), so I ended up creating a custom progress bar.
It is pretty simple
Create 2 straight straight bars, one black and other of any color (if you want something more fancy, it is upto you)
Add the bars to drawable and then to your layout xml in hidden mode. The colored bar exactly on top (superimpose) of black bar
Now where you want to show the progress bar, make the black bar visible first, and adjust the width of colored bar (on top of black bar) as per the progress.
This will give you proper functionality of the progress bar.
As you are playing around only with imageviews, you have full control over when to show or hide the bar. Also by default it will not freeze the view. You can freeze at will by capturing onTouch event.
I have an app where students at my school can download course content that professors upload. Everything works great, except I have no progress bar dialog. I recently switched the app over to using fragments, so the old dialog I was using broke.
Anyway, I was thinking that instead of having a dialog display the progress bar, I could use the background of the item that was clicked as the progress bar.
Here is a screenshot of the app:
http://dl.dropbox.com/u/4439149/Screenshot_2012-09-27-15-06-43.png
And here is a mocup of how I imagine it working:
http://dl.dropbox.com/u/4439149/42an8-CTWBJpw391zDSBs5MAiuIhibcsRWhZGwdvmTE%20copy.png
I cannot for the life of me think of how this should be done. I am hoping someone could just give me a push in the right direction.
Thanks,
David
Check out Clip Drawable. You can set the background of your row to a ClipDrawable that holds the color or another drawable that you want to show for progress, then set the level (progress) while downloading.
Have you tried changing your row.xml to be a frame layout and just have a ProgressBar that fills the entire row? You can then put this behind the layout you currently have in your row.xml.
In my app i make the app fullscreen. Means android title bar and notification bar is hidden here.
But when i click on the spinner the hidden notification bar gets visible for fraction of seconds. It is not happening with all the spinners in my app. But where i use a array,generated by a loop execution in the spinner adapter, it is only happening in that case.
I have come to know that it is a known bug in android. I also use the following style in spinner to resolve it.
In my app i make the app fullscreen. Means android title bar and notification bar is hidden here.
But when i click on the spinner the hidden notification bar gets visible for fraction of seconds. It is not happening with all the spinners in my app. But where i use a array,generated by a loop execution in the spinner adapter, it is only happening in that case.
I have come to know that it is a known bug in android. I also use the following style in spinner to resolve it.
true
true
#null
But still i cant solve this problem..
If anyone has any solution please let me know.
add this line before setContentView():
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Then u use requestWindowFeature(Window.FEATURE_NO_TITLE); in activity and it must be before of the setContentView(....) method