我在我的 android 应用程序中创建了一个 ProgressDialog。但我遇到的问题是在它实际完成工作时停止旋转轮子。这是我的代码。我怎样才能让它在我进行其他工作时不断旋转轮子?
button5.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
System.out.println("Button5");
//Handler to make the please wait message
final ProgressDialog myProgressDialog = ProgressDialog.show(
FoodSubstitutesActivity.this, "Please wait...",
"Getting most recent updates...", true);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
//DO STUFF - STOPS SPINNING WHEEL UNTIL THIS PART IS COMPLETE.
myProgressDialog.dismiss();
}
}, 500);
}
});
最佳答案
你为什么不尝试这样做呢?
final ProgressDialog dialog = ProgressDialog.show(this, "Title",
"Message", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
dialog.dismiss();
}
};
Thread checkUpdate = new Thread() {
public void run() {
//
// YOUR LONG CALCULATION (OR OTHER) GOES HERE
//
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
取自:http://www.tutorials- android.com/learn/How_to_display_a_progress_dialog_while_computing.rhtml
关于Android ProgressDialog 停止旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9628803/