I have a algorithm that need about 4-5 sec to get all the contacts from sim and bind them in my autocompletetextview (which happens in onCreate) so while that happens how can i create a dialog that will show like loaing and percentage or a progress bar... pls some reference or help:D
3 Answers
you have to used the ProgressDialog: http://developer.android.com/reference/android/app/ProgressDialog.html
It can show a indeterminate progress bar or a percentage. To update the percentage bar, you'd possibly need to use the class AsyncTask. I put a link which shows the two classes working together: http://sites.google.com/site/androidhowto/how-to-1/asynctasks-with-progressdialogs
I'm adding a more useful link: http://www.codeproject.com/Articles/162201/Painless-AsyncTask-and-ProgressDialog-Usage
Comments
Use AsyncTask, it has helpful methods namely
protected void onPreExecute(){
//Show a dialog here
}
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
protected void onPostExecute(Long result) {
showDialog("Downloaded " + result + " bytes");
}
You can publish your percentage progress in onProgressUpdate method and in onPostExcecute dismiss the dialog
Comments
You should write the part updating the progressbar as an AsyncTask to see the loading lively. You can also use Handlers.
this can help: http://developer.android.com/reference/android/os/AsyncTask.html