Reputation: 17340
Can I use progress bar in android, without the thread?
HERE IS CODE OF MY CURRENT WAY OF IMPLEMENTING PROGRESS DIALOG
// Adding Progress bar
String[][] data; //Global variable
//called on onCreate() or onItemSelected
final ProgressDialog myProgressDialog;
myProgressDialog = ProgressDialog.show(ListingPage.this,"Please Wait", "Loading Date", true);
new Thread() {
public void run() {
try{
setSelected();
sleep(5000);
} catch (Exception e) { }
myProgressDialog.dismiss();
}
}.start();
populateList(Split.splitToTwoDimArray(data)); // populates the list view
HOPE ABOVE HELPS, IF USING THREAD THE LIST IS NOT BEING POPULATED.
Upvotes: 0
Views: 1360
Reputation: 28665
Sure, you can always set the progress manually via
progressBar.setProgress(int progress);
Above question/added code is a bit confusing cause you asked how to use the progress bar without a thread but now in your code you're using a thread. I thought that you initially wanted to avoid.
Anyway, maybe you should use an AsyncTask instead of the Thread, which allows you to modify anything in the main UI thread.
https://sites.google.com/site/androidhowto/how-to-1/create-a-custom-progress-bar-using-asynctask
http://developer.android.com/reference/android/os/AsyncTask.html
Upvotes: 1