简体   繁体   English

如何在课程中调用载入微调器

[英]How to call a loading spinner within a class

I am trying to load a "loading spinner" from a class and I am wondering what is the best way to achieve this. 我正在尝试从课程中加载“加载微调器”,我想知道实现此目标的最佳方法是什么。 In my class there is a Asynch task in which I want the spinner to start and finish. 在我的课堂上,有一个Asynch任务,我希望微调器启动和完成。 I have created my loading spinner in a layout now what I am trying to do is I want the spinner to be shown while the Asynch task finishes. 我现在已经在布局中创建了加载微调器,我想要做的是我希望在Asynch任务完成时显示微调器。

Here is my class: 这是我的课:

public class ClusterManager extends ClusterManager {

public ClusterManager() {
    super();        
}

private void reload() {

    new AsyncTask<Void, Void, Void>()
    {
        @Override
        protected Void doInBackground(Void... params)
        {
            //Start spinner here
        }

        @Override
        protected void onPostExecute(Void aVoid)
        {
            //Stop/Remove the spinner
        }
    }.execute();

}

And my Custom spinner 还有我的自定义微调器

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LoadingSpinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleLarge"
android:layout_centerHorizontal="true">

</ProgressBar>

I think you can load a ProgressDialog in the constructor of the class and show it of hide it in the two callbacks. 我认为您可以在类的构造函数中加载ProgressDialog并在两个回调中将其隐藏。

Another alternative is to pass a listener from the activity or fragment and behing notify when to show or hide. 另一种选择是从活动或片段中传递一个侦听器,并提示何时显示或隐藏。 In this way you can have to progress bar in your layout. 这样,您就必须在布局中显示进度条。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM