如何在FireBaseHandler中实现ProgressBar [英] How to implement ProgressBar in FireBaseHandler

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

问题描述

我有问题,片段包含内容,我想在Firebase加载内容的同时添加简单的ProgressBar.我该怎么办?在哪里? (我尝试添加onDataChange,但它不起作用,下面的代码)

I have the problem, Fragment has content and I want to add simple ProgressBar while of Firebase loading content. How can I do this and where ? (I try to add in onDataChange but it dosn't work, code below)

public void onDataChange(DataSnapshot dataSnapshot) {
            progressBar.setVisibility(View.VISIBLE);
            mContentLayout.setVisibility(LinearLayout.GONE);

            for (final DataSnapshot snapshot : dataSnapshot.getChildren()) {
                item = snapshot.getValue(Item.class);
                if(item.isSales()) {
                    arrayOfItemProduct.add(item);
                }
            }
            adapter.notifyDataSetChanged();

            progressBar.setVisibility(View.GONE);
            mContentLayout.setVisibility(LinearLayout.VISIBLE);
        }

推荐答案

要解决这个问题,您可以在片段的.XML布局文件中添加以下代码行:

To sovle this, you can add in your .XML layout file of your fragment the following lines of code:

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progress_bar"
    android:layout_centerInParent="true"
    style="@style/Widget.AppCompat.ProgressBar"/>

这意味着每次启动片段时,都会显示ProgressBar.

This means that everytime you start your fragment the ProgressBar will show up.

progressBar变量定义为全局变量,然后在您的fragmnet中的onCreateView()方法内找到它,如下所示:

Define the progressBar variable as a global variable and then find it in your fragmnet inside the onCreateView() method like this:

progressBar = yourFragmentView.findViewById(R.id.progress_bar);

然后在您的onDataChange()方法内部使用以下代码:

And then inside your onDataChange() method use the following code:

if (progressBar != null) {
    progressBar.setVisibility(View.GONE);
}

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

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