我正在开发一个Android应用程序,我在其中发送和接收来自parse.com服务器的一些数据。现在我想在我的任何方法上应用进度条,这涉及任何发送和接收数据,例如在登录时我想用百分比放入进度条,当百分比完成到100时,进度条应该被解雇。
我的代码如下:
public void login(){
showLoadingDialog(); // <===Progress Bar should start here
ParseUser.logInInBackground(email, password,
new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
dismissLoadingDialog();// <===Progress Bar should end here
if (user != null) {
showMessage("Logged In!");
user = ParseUser.getCurrentUser();
CURRENT_USER = user;
try{
CURRENT_USER.getParseObject("infor").fetchIfNeededInBackground(
new GetCallback<ParseObject>() {
public void done(ParseObject curreno,ParseException e) {
if(e==null){
if (currentUserinfo == null) {
String abc = " ";
curreno();
} else {
Intent intent = new Intent(LogInActivity.this,NewActivity.class);
startActivity(intent);
}
}else{
}
}
});
}
catch (NullPointerException e2) {
createUserinfo();
}
} else {
showMessage("There was some problem");
}
}
}); }
progress = new ProgressDialog(this);
public void open(View view){
progress.setMessage("Downloading Music :) ");
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 = 0;
while(jumpTime < totalProgressTime){
try {
sleep(200);
jumpTime += 5;
progress.setProgress(jumpTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
t.start();
}