gpt4 book ai didi

java - 如何在android中启动和停止进度条?

转载 作者:行者123 更新时间:2023-11-29 08:33:28 25 4
gpt4 key购买 nike

我有一个调用第二个 java 类的 Activity 。我想在调用第二个类后显示进度条,然后返回到正常的 Activity 执行。我找到了一些其他线程,但我无法让进度条停止。

最佳答案

here 上有一个完整的例子.

引用:

Declare your progress dialog:

ProgressDialog progress;

When you're ready to start the progress dialog:

progress = ProgressDialog.show(this, "dialog title",
"dialog message", true);

and to make it go away when you're done:

progress.dismiss();

Here's a little thread example for you:

// Note: declare ProgressDialog progress as a field in your class.

progress = ProgressDialog.show(this, "dialog title",
"dialog message", true);

new Thread(new Runnable() {
@Override
public void run()
{
// do the thing that takes a long time

runOnUiThread(new Runnable() {
@Override
public void run()
{
progress.dismiss();
}
});
}
}).start();

ProgressDialog 已弃用,因此您可能需要使用 ProgressBar。

我找到了 this post关于删除其中一个。

Well, I think this is rather ridiculous, but here is how I fixed it.

In my xml for the ProgressBar, I added android:visibility="gone" to hide it by default. Then, in my code, I first told it to display (View.VISIBLE) before it tried getting the server list, then I told it to hide (View.GONE) after it was done. This worked (I could see the progress indicator while the data loaded, then it went away). So I suppose I couldn't get it to hide in the code because the code is not what forced it to be visible to begin with... That seems like a bug to me.

关于java - 如何在android中启动和停止进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45941107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com