如何避免ProgressDialog在Android中 [英] How to avoid ProgressDialog in Android

查看:182
本文介绍了如何避免ProgressDialog在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对话框@ Android开发者说要避免ProgressDialog指示加载,而是,把一个活动的指标权布局。

Dialogs @ Android Developer says to avoid ProgressDialog to indicate loading, and instead, to put an activity indicator right in the layout.

进展和放大器;活动@ Android开发者讨论活动指标,但没有指定使用的类。我已经没有运气像ActivityBar,ActivityCircle或ActivityIndi​​cator名称搜索Android的类。

Progress & Activity @ Android Developer discusses activity indicators, but doesn't name the classes used. I've had no luck searching for Android classes with names like ActivityBar, ActivityCircle, or ActivityIndicator.

我在哪里可以找到Android的支持文档(教程,范例,或者API文档),用于包括活动指标权在我的布局,避免ProgressDialog?

Where can I find documentation (tutorials, examples, or API documentation) on Android's support for including activity indicators right in my layout, avoiding a ProgressDialog?

更新: full.stack.ex我指出了正确的答案

Update: full.stack.ex pointed me the right answer.

首先,请在活动的onCreate()方法的以下code调用的setContentView()之前:

First, include the following code in the Activity's onCreate() method before invoking setContentView():

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

接下来,只需加载(例如发射了一个AsyncTaskLoader),使用此电话进行微调之前出现:

Next, just before loading (e.g. firing up an AsyncTaskLoader), use this call to make the spinner appear:

setProgressBarIndeterminateVisibility(true);

最后,装载完成后,再次隐藏微调:

Finally, after the load is completed, hide the spinner again:

MainActivity.this.setProgressBarIndeterminateVisibility(false);

宾果!无需ProgressDialog。使得微调可见,似乎装载在模拟器大大减缓(需要花费几分钟,而不是秒),而不是我的实际电话。我不知道是否有什么办法可以使微调使用较少的CPU周期。

Bingo! No ProgressDialog required. Making the spinner visible seems to slow down loading considerably in the emulator (it takes minutes instead of seconds), but not on my actual phone. I'm not sure if there's any way to make the spinner use fewer CPU cycles.

推荐答案

这不是真的从没有对一个窗口功能的文档显而易见的。

It's not really obvious from the documentation that there's a window feature for that.

这是一个内置的进度指示器:

It's a built-in progress indicator:

Activity.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

<一个href=\"http://developer.android.com/reference/android/app/Activity.html#requestWindowFeature%28int%29\" rel=\"nofollow\">developer.android.com/reference/android/app/Activity.html#requestWindowFeature(int)

这篇关于如何避免ProgressDialog在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆