Several setMessage updates (ProgressBar)
new Thread() {
public void run() {
try {
Progress.setMessage("Scanning Apps ...");
int CurrentNumber = 0;
while (CurrentNumber <= 99) {
Progress.set开发者_JAVA百科Progress(CurrentNumber);
Progress.setMessage(CurrentNumber + "");
sleep(100);
CurrentNumber ++;
} catch (Exception e) {
}
}
}.start();
So.. this code is not working :(
What am I doing wrong?
Without Progress.setMessage(CurrentNumber + "");
it is working perfectly...
write handler e.g.
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
//set message here
}
};
Try looking at AsyncTask which handles progress updates, giving you a chance to set your progress message on the UI thread.
I'm assuming that Progress is an instance of ProgressDialog. You can only update the UI on the UI (main) thread. Read about threading and the UI on the dev site.
精彩评论