Reputation: 6974
How I can set dynamically set the progressbar status after reading a value from db SQLite?
I have this code.
int i = 0;
while (!c.isAfterLast()) {
i++;
pb.setProgress(i)
}
But my problem is that progress bar is update only at finish while so without "liveEffect"
Upvotes: 0
Views: 115
Reputation: 6974
I resolved my problem with Handler and Thread.sleep (for simulate live)
new Thread(new Runnable() {
public void run() {
do {
mProgressStatus++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mHandler.post(new Runnable() {
public void run() {
pb.setProgress(mProgressStatus);
}
);
} while (c.moveToNext());
}
}).start();
Upvotes: 0
Reputation: 9388
You can use runOnUiThread method of Activity class:
runOnUiThread(new Runnable() {
@Override
public void run() {
pb.setProgress(i);
}
});
More here: https://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable)
Upvotes: 1
Reputation: 3201
Actually, execution time is too low that by live effect not appear . take large cursor around 10000 value then apply loop now you can see progress
Upvotes: 0