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 .
Related
I want to know how to show an image which is in my case a gif loading screen to show when opening the layout of web view to give it time to give time to load contents in web view.
Either i should use a timer for the image to load or anything else.
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(net_fragment_1.this,loadinganimate.class);
startActivity(i);
finish();
}
},1000);
I have tried this code but it is crashing.
Note- i am keeping loadinganimate class in the same package.
But whenver i am keeeping in different package and calling it by full path like com.xyz.xyz.loadinganimate.class
it is just showing this class and not resuming to the original windows after a period of time...
remove handler and add these lines in to your code
if (webView.isShown()){
loadinganimate.setVisibility(View.INVISIBLE);
}
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();
}
button.performClick();
For software demonstration purposes, I want to show the user interface updating after each button performClick(). For example, if the Activity was a calculator I can currently simulate the pressing of buttons [1], [2] and [3] using
btn1.performClick();
btn2.performClick();
btn3.performClick();
However, these updates to the EditText too quickly with no visible pause, i.e. it appears "123" are written to the screen simultaneously. What I want is:-
btn1.performClick() updates UI so people can physically see only button press updated to the EditText before the next button does. Similarly with btn2.performClick() and then btn3.performClick().
You may want to use a library like Robotium, and use Solo.waitForText Method to do what you want.
The problem is that we can not determine in advance the time that it will take to display the text, as it depends on the content of your onClick method.
It's why Robotium may be useful for what you want.
You can either use
Thread.sleep(delay);
or use
handler.postDelayed(Runnable,delay);
Use handler for btn2.performClick() and btn3.performClick() like...
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
// do something after 100ms
btn2.performClick();
}
}, 100);
I wrote application that contain 2 activities.
In the first one - i need to give the user the option to choose image from the gallery and i send this image to some server.
The Server return some result - and if the result is OK i need to show the second activity.
The problem that i have ..
when sending the image - i see that the screen is become black ...
I want to avoid this and show some nice GUI of 'please wait' - how can i do it ?
i want to make this sending image to the server to be from other thread - how can i do it from android ? how to define new thread with callback that will be called when the thread is done ?
Thanks for any help.
Use an asynctask. It would go something like this:
public void sendImage() {
SendToServer.execute();
}
protected class SendToServer extends AsyncTask<Void, Boolean, Void>
{
#Override
protected void onPreExecute()
{
//display your dialog
}
#Override
protected Boolean doInBackground(Void... arg0) {
//code to send your image to the serve
}
#Override
protected void onPostExecute (Boolean updateSuccess)
{
//close your dialog
//If image was successfully sent open your other activity
}
}
For question number 1:
You should use a ProgressDialog or a ProgressBar in order to show to the user that an operation is being executed. For more information you can check here: http://developer.android.com/reference/android/app/ProgressDialog.html
For question number 2:
A good solution would be to use AsyncTask for this operation which gives you a set of callback functions to control the operation. For more information you can check here: http://developer.android.com/reference/android/os/AsyncTask.html
Hope this helps for now!
you can define your custom layout and use the Activity.setContentView method to put whatever you want in your GUI. For instance you can put a ProgressBar widget.
As you have noticed, you wrote your android app in Java SE. Thread are fully supported.
This question has an answer which addresses the problem. Use that answer as a start, and let us know if you have any problems with some specific part.
Download image for imageview on Android
Good luck