我无法获得进度对话框以显示我何时需要它。我已经尝试将它放在我的asyncTask中,ui类和它自己在ui上运行的线程并且没有一个工作。任何人都可以帮助我吗?
调用progressDialog方法的方法:
public void shareTest(View view){ //method called to jump to share activity if criteria matched
if(checkInputs()) { //call to check inputs
Share start = new Share();
boolean isConnected=start.connectToServer(); //connectToServer
Intent intent = new Intent(HomeScreen.this, Share.class); //create intent to move to share class from this activity
startProgressDialog();
if (isConnected) { //check to see if isconnected was succesful
if (Share.matchFound ){ //check to see if a match was found
progress.dismiss();
startActivity(intent); //if true jump to share activity
} else {
while (!Share.timedOut) { //While the time has not timedOut
if (Share.matchFound) { //if a share has been found
startActivity(intent); //start share activity
break; //if true then break
}
}
if (Share.timedOut) {
//send an notice that a match wasn't found
sendToast(getString(R.string.noShare)); //if not true then send Toast
}
}
}
else sendToast(getString(R.string.errServCon)); //if connection to server failed then send toast
}
}
这是方法:
void startProgressDialog(){
new Thread(new Runnable() {
@Override
public void run() { //creates a new runnable thread
// Issue command() on a separate thread
while (!Share.matchFound) { //while havent been asked to disconnect //if a new location has been recieved
activity.runOnUiThread(new Runnable() {
@Override
public void run() { //run on the ui thread act
progress.show(); //call the method that does the update
}
});
}
progress.dismiss();
}
}).start();
}
答案 0 :(得分:1)
声明一个这样的全局变量:
ProgressDialog progress;
只要您想要显示进度,请粘贴以下代码:
progress = ProgressDialog.show(this, "Please wait",
"Loading..", true);
完成后,只需将其解雇:
progress.dismiss();