[英]How to start and stop progressbar in android?
I have an activity that calls a second java class. 我有一个活动,它调用第二个Java类。 I want after the second class is called to show a progressbar and then return to normal activity execution.
我想在第二个类被调用后显示进度条,然后返回到正常活动执行。 I found some other threads but i couldn't make the progressbar to stop.
我发现了其他一些线程,但无法使进度条停止。
There's a full example over here . 有过一个完整的例子在这里 。
Quote: 引用:
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 is deprecated, so you might want to use a ProgressBar. 不推荐使用ProgressDialog,因此您可能要使用ProgressBar。
I've found this post about deleting one of them. 我发现了有关删除其中一个的帖子 。
Well, I think this is rather ridiculous, but here is how I fixed it.
好吧,我认为这很荒谬,但这是我修复它的方式。
In my xml for the
ProgressBar
, I addedandroid:visibility="gone"
to hide it by default.在我的
ProgressBar
xml中,我添加了android:visibility="gone"
以默认隐藏它。 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.然后,在我的代码中,我首先告诉它在尝试获取服务器列表之前先显示(
View.VISIBLE
),然后在完成后告诉它隐藏(View.GONE
)。 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.
因此,我想我无法将其隐藏在代码中,因为代码并不是迫使它开始可见的原因……对我来说,这似乎是个错误。
Its very Simple: 非常简单:
to show a Progress 显示进度
ProgressDialog dialog = ProgressDialog.show(getContext(), "Title", "Message");
and to stop it: 并停止它:
dialog.dismiss();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.