This is what I am doing
ProgressBar myProgressBar = (ProgressBar) findViewById(R.id.progressBar);
myProgressBar.setVisibility(View.VISIBLE);
fetchData();
mainView();
myProgressBar.setVisibility(View.INVISIBLE);
But the progressbar does not show.
fetchData takes around 5 seconds and while it is running, the progressbar should be shown.
I guess the display is not updated while the App is busy. Is there a way to update the display before I call fetchData?
You should try using an AsyncTask. This will allow you to run fetchData() using the doInBackground(...) method and post progress using onProgressUpdate(...).
In the layout file give android:visibility="visible" for the ProgressBar. And when the content is loaded u set visibity to invisible.
Related
I have a progress dialog that takes 3 minutes to fill the progress.
If i get response from server earlier I want to fill progress to 100%, and then disables it.
This is my code, but it does not fill the progress bar to 100%.
progressBar.setProgress(100);
progressBar.cancel();
progressBarLayout.setVisibility(View.GONE)
I have a separate layout for progress dialog, that i disable when i set progressBar to 100. May be that's the reason it fails to render the progress dialog.
There might be an issue here:
The progressBar has a setMax method. So if your max is set to 2 (for example) if you use progressBar.setProgress(1); it will advance to 50%.
If you want to always fill it completely, perhaps using something like:
progressBar.setProgress(progressBar.getMax());
Possible issue:
Im not sure if you should change this in the UIThread, because you are touching the UI, I would recommend to check it.
Hope this helps.
Your code fills it to 100% but immediately makes it disappear, hence you're not seeing it. Try adding the code about turning your bar invisible in a runnable that starts only after you get the confirmation from the server
Runnable r = new Runnable() {
#Override
public void run() {
progressBarLayout.setVisibility(View.GONE)
}
}
then create a handler for ypur runnable:
Handler handler = new Handler();
When you get the response from the server tell the handler to wait for x seconds and run the runnable
handler.postDelayed(r, 2000); //here it waits for 2 seconds (2000 mills)
I have used Google Place Picker API in my app
So Place Picker takes time to load, so I want to use ProgressBar for a certain time till the api is completely loaded
and is there any way to work with complex UI
for eg my main page contains lots of data and it takes around 5-6sec to completely load it,so is there a way to add progressbar over there also?
please Help i am new to android
Declare your progress dialog:
ProgressDialog progress;
When you're ready to start the progress dialog:
progress = ProgressDialog.show(this, "dialog title",
"dialog message", true);
and to make it go away when you're done:
if (progress != null) {
progress.dismiss();
}
I'm trying to display a determinate progress dialog with a bar, however, I can't get it to working. Here is how I create it:
dialog = ProgressDialog.show(from, "Posting...", "Uploading...");
Then on UI thread (calling within runOnUiThread), I'm calling:
dialog.setIndeterminate(false);
However, when I inspect after it (both immediately after setting, and in progress handler afterwards which is invoked independently while uploading a file), it's isIndeterminate() method returns true. I've also tried:
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
But it also didn't change anything (still, indeterminate indicator is spinning instead of a progress bar). I've set it's max to 100, and my progress handler is being invoked with perfectly valid values between 0 and 100, and I'm calling all dialog methods on UI thread, but nothing changes. What am I doing wrong?
You can't change the style of the progress after showing the ProgressBar what you can do is to prepare it first then show it.
progressDialog = new ProgressDialog(this);
progressDialog.setTitle("title");
progressDialog.setMessage("message");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.show();
OR
dialog = ProgressDialog.show(from, "Posting...", "Uploading...", false);
I have an animation with 12 images that displays as a loading image. It works fine on its own, but when I use my httpClient class to get content from the online db, it freezes completely and when the content is done fetching, you can see the animation stopped on a different image.
How can I make that the image load while the content is being fetched from the db ?
Here is some code:
Class members:
ImageView loading;
AnimationDrawable loadAnimation;
onCreate:
LinearLayout main = (LinearLayout) findViewById(R.id.loading);
loading = new ImageView(this);
loading.setImageResource(R.drawable.loading);
loadAnimation = (AnimationDrawable)loading.getDrawable();
main.addView(loading);
I use this to start the animation before the content is fetched:
loadAnimation.start();
And this when it is done fetching:
loadAnimation.stop();
The reason this is happening is that you are performing database operations on the main thread, which freezes the UI while your blocking code is executing. To avoid this, you need to perform those operations in a different thread. Look into using AsyncTask to see an example of how to download files asynchronously.
In your case, start the animation in onPreExecute() and stop it in onPostExecute().
I am new to Android. In my application I want to add an process bar(an image), this should indicate that something is in process and after completion hide this precess bar.
As if i add user detail, On click on add button this process bar should be displayed.
How can i do it, please suggest.
Thanks.
Code I used:
progressDialog = ProgressDialog.show(AddTicketActivity.this, "", "Loading...");
new Thread() {
public void run() {
try{
sleep(10000);
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
progressDialog.dismiss();
}
}.start();
The problem with it is , it is hardcoded sleep(10000) whereas what i want is it to be dependent on how much time my process takes to add or fetch data.
I am not getting where to put code which is executing on onclick of button.
I hope you got my point
Thanks again.
For that you can use either ProgressDialog or ProgressBar.
Now, To display Progress bar and during that perform task in background, you should implement AsyncTask.
In onPreExecute() method, display the ProgressBar or make it visible again like: progressbar.setVisibility(View.VISIBLE);
In doInBackground() method, perform the background task, i.e. add user detail in your case
In onPostExecute() method, just hide the ProgressBar using the progressbar.setVisibility(View.INVISIBLE);
Well if you just want to show an image, you can place it on a RelativeLayout with visibility=gone
and then just control when to show or hide it.
another way is the typical progressDialog in Android
Or use a progress bar (spinning wheel) it's more user friendly and droid friendly .
Take a look at the Form widgets on Eclipse .