我有一个progressBar对话框,当我单击我的按钮时,对话框出现并显示一条消息,但进度保持在0%,然后进入下一个活动,而不是按预期从0%-100%开始。谁能看到我出错的地方?
package win.jay.todo.list;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.app.ProgressDialog;
import android.view.Menu;
public class Welcome extends Activity {
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
progress = new ProgressDialog(this);
}
//Onclick - go to Tasks
public void doStuff(View view) {
Intent intent = new Intent(Welcome.this, Tasks.class);
startActivity(intent);
progress.setMessage("Finding tasks...");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(true);
progress.show();
final int totalProgressTime = 100;
final Thread t = new Thread(){
@Override
public void run(){
int jumpTime = 5;
while(jumpTime < totalProgressTime){
try {
Thread.sleep(200);
jumpTime += 5;
progress.setProgress(jumpTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
t.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
}