I parse the .html page and take set of checkbox, than I add checkboxes to layout and setContentView(layout). But parsing is slow, and I want to create loading window during data is loading. I don't know how to do it, help me please. Thank you for, anyway.
For that you can implement AsyncTask (Painless Threading), implement ProgressBar inside the onPreExecute() method of AsyncTask.
As i have marked it is known as Painless Threading as we developer need not to bother about to start/pause/stop the thread, it is managed by Android itself.
Update:
You can also show ProgressDialog inside the onPreExecute() method and then hide the same in onPostExecute() method. For the same, i suggest you to go through this article, really helpful: https://sites.google.com/site/androidhowto/how-to-1/asynctasks-with-progressdialogs
You can do this using a progress dialog. There is a tutorial on the Android Developers Website, and this is where It starts to explain:
A ProgressDialog is an extension of the AlertDialog class that can
display a progress animation in the form of a spinning wheel, for a
task with progress that's undefined, or a progress bar, for a task
that has a defined progression. The dialog can also provide buttons,
such as one to cancel a download.
The Link is here: http://developer.android.com/guide/topics/ui/dialogs.html
Related
I have an app where an action by the user sometimes causes the app to get data from the server before it can be displayed, like getting detail info for an item (the info is too large to preload it for all items) or refreshing all data.
While this is in process i don't want the user to do anything else. What is the guideline to display a "please wait" message? Ideally it should be possible for the user to cancel the request if he wants to.
I can do it with an alert dialog, but the operation usually takes just half a second to a second, and imo it looks really strange for an alert dialog to pop up just for a moment, maybe not even long enough to be able to read the message.
Another option i see is the snack bar, but it doesn't prevent the user from doing anything else or navigate away.
Is there a guideline or best practice what to do in this scenario?
I'm using Xamarin.Android, but i don't think that matters.
You can show a loading circle in place where the content being loaded will be displayed like this. When it finishes, replace the loading circle with the content.
Actually "i don't want the user to do anything else" is not acceptable in most Android design patterns. Android app should allow the user to take control of the app.
About canceling the request, you can add a cancel button near the loading circle, or add a cross inside the circle which will stop the process when being pressed. The latter is preferred.
For more patterns see this.
About progress dialog
As far as I know, progress dialog which block the user interaction is discouraged in the new Android. But I am sorry that I cannot find the reference yet, maybe somewhere in Material Design guidelines document. However, because you are the developer, it's all up to you :D.
Check out the documentation on AsyncTask.
I would do the long running task in an AsyncTask, show a ProgressDialog in it's onPreExecute method and hide it after it finised, in onPostExecute.
To prevent the user from closing the dialog you can use the Dialog.setCancelable() method.
You can define a custom layout for your Dialog and set it via the setContentView() method.
I have searched everywhere and read the official doc of Google. But I still don't see the difference between them.
When should we use ProgressBar and when should we use ProgressDialog?
ProgressBar:
ProgressDialog:
The ProgressBar is a View, ProgressDialog is a Dialog.
While the answers here are informative, none really address the question.
Use a ProgressDialog when you want to prevent the user from
interacting with the application while waiting. The Dialog aspect
freezes the user from doing anything until it is dismissed. Note how the UI behind the ProgressDialog is grayed-out and inaccessible.
Use a ProgressBar to indicate that something in your app is still
waiting (loading, thinking, etc.) while the user may still interact with
other parts. In this image, the user can still fill out forms while waiting for the gps to respond.
(Thanks to Johnny S for the image of the ProgressDialog.)
ProgressBar is a View (like TextView, ImageView, Button, etc..), which can be used in your layout to show some progress.
ProgressDialog is a Dialog with 'built-in' ProgressBar. Dialogs can be used to make user wait while something is being computed. ProgressDialog makes it easier to show progress of your computation in dialog.
In addition to the differences pointed out in the rest of answers, you should take into account the following recommendation from Dialogs # Android Developer:
Avoid ProgressDialog
Android includes another dialog class called ProgressDialog that shows
a dialog with a progress bar. However, if you need to indicate loading
or indeterminate progress, you should instead follow the design
guidelines for Progress & Activity and use a ProgressBar in your
layout.
It may be also usefull to consider the following answers:
https://stackoverflow.com/a/12559601/2482894
How to avoid ProgressDialog in Android
When your iterations is countable (doing operations in loop, executing code x times etc.) use ProgressBar, if task is not countable status (like invoking web service) use ProgressDialog
From the android documentation
ProgressBar:Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has
progressed; the application can change the amount of progress
(modifying the length of the bar) as it moves forward. There is also a
secondary progress displayable on a progress bar which is useful for
displaying intermediate progress, such as the buffer level during a
streaming playback progress bar.
ProgressDialog:A dialog showing a progress indicator and an optional
text message or view. Only a text message or a view can be used at the
same time.
I am building an android app which will download some data and display it to the user. Now I need to show a circular progress bar until the data is downloaded. The download will begin on a button click. How can I achieve this? Sample code would be very helpful.
You need to use an AsyncTask to execute your download and ProgressBar instance to show a circular progress.
There are many resources you can find which describe exactly how to use the combination to do what you want.
Check Android AsyncTask class for what you want to achieve.
Basically you start showing a ProgressDialog in the onPreExecute of AsyncTask and dismiss it in onPostExecute when your background job is done.
Check these also.
android how to work with asynctasks progressdialog
http://twigstechtips.blogspot.com/2011/11/for-my-app-moustachify-everything-i-was.html
http://javatech.org/2011/02/discovering-android-opening-a-progress-dialog-with-asynctask/
I have a program that copies a file to the sd card. The program takes a while to run, and now it just freezes while the file is being copied.
I saw some other programs that have a animation of a wheel spinning in the center of the screen while the file is being down loaed.
I tried to google spin control, but this brought up animation about a selector control using spinning wheels.
Is this feature built into the android?
Use a ProgressBar widget with indeterminate="true". You can use a ProgressDialog, read http://developer.android.com/guide/topics/ui/dialogs.html
Also, learn about threads, as you should be doing your file save in a background thread. http://developer.android.com/guide/components/processes-and-threads.html
You should use an AsyncTask to download the file. This will prevent your UI from freezing, and also easily allows you to show progress information if you want. If you want to let it download in the background, and let the user continue using the app, that's doable as well.
You can find an AsyncTask in one of my open source projects that downloads a file and shows the progress information using a progress bar here. You can change the style of the progress dialog to suit your needs.
I'm assuming you're using some sort of AsyncTask to download it?
If this is the case you can make an indeterminate progress bar start spinning right before you call task.execute() and then in onPostExecute() you can set the progress bar's visibility to view.GONE
here is an example on progress bars: http://codehenge.net/blog/2011/06/android-development-tutorial-progressbar-example/
Is it possible to get a progress dialog (a "loading..." one, not a percentual one) without using threads? I would even accept a custom dialog with an static image instead of the loading animation. So, is it possible? How?
Its not possible.
I would recomend using an AsyncTask which is what the Android Team made to simplify threading.