Firebase在滚动时动态加载数据 [英] Firebase load data dynamically on scrolling

查看:203
本文介绍了Firebase在滚动时动态加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何在使用Firebase滚动时动态加载数据。如果我使用Firebase查询数据,则所有数据都必须一次加载或总是更改数据。我想要使​​用Firebase的限制加载数据,并达到此限制后,加载更多的数据和越来越多。



它基本上就像Facebook的时间表 - 作为社交网络。



例如:我想从Firebase获取最新的记录,达到50个。达到此限制后,我将下载下一个50个数据。我想要使​​用 RecyclerView 而不是 FirebaseRecycler class。

FirebaseRecyclerAdapter不能解决我的问题。感谢帮助。 Trully,我需要像点视图布局的Facebook时间线loadind数据,并加载数据Firebase(50到50)下载50个数据,达到极限,点视图数据库的底部布局的更多数据到50)。
$ b

您可以帮我吗?

解决方案

b

  //实现滚动监听器
public void implement ScrollListener(){
$ b $ recyclerView
.addOnScrollListener(new RecyclerView .OnScrollListener(){
$ b @Override
public void onScrollStateChanged(RecyclerView recyclerView,
int newState){

super.onScrollStateChanged(recyclerView,newState) ;

//如果scroll状态是touch scroll,那么设置userScrolled
// true
if(newState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
userScrolled = true;




@Override
public void onScrolled(RecyclerView recyclerView,int dx,
int dy){
super.onScrolled(recyclerView,dx,dy);

//这里从布局管理器获取子项数,项目数和visibleitems
//

visibleItemCount = mLayoutManager.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
pastVisiblesItems = mLayoutManager
.findFirstVisibleItemPosition();

//现在检查userScrolled是否为true,并检查
//该项是否结束,然后更新回收视图并将
// userScrolled设置为false
if (userScrolled
&&(visibleItemCount + pastVisiblesItems)== totalItemCount){
userScrolled = false;

RefreshData(oldestPostId);
}
}
});
}


I need know how to load data dynamically on scrolling with Firebase. If I query data with Firebase, all data must be loaded once time or always data changed. I want load data with Firebase per limit, and after reach this limit, load more data and more and more.

It would basically be like a timeline of Facebook - as a social network.

For example: I want to get the latest records from Firebase at limit 50. After reach this limit, I will download the next 50 data. I would like use RecyclerView and not FirebaseRecycler class.

FirebaseRecyclerAdapter not solve my question. Thanks for help. Trully, i need loadind data like facebook timeline of point view layout, and load data Firebase (50 to 50. Download 50 data, reach limit, load more data of bottom layout to 50) of point view Database.

Could you help me?

解决方案

This works perfectly.

// Implement scroll listener
public void implementScrollListener() {

    recyclerView
        .addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView,
                                             int newState) {

                super.onScrollStateChanged(recyclerView, newState);

                // If scroll state is touch scroll then set userScrolled
                // true
                if (newState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
                    userScrolled = true;

                }

            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx,
                                   int dy) {
                super.onScrolled(recyclerView, dx, dy);

                // Here get the child count, item count and visibleitems
                // from layout manager

                visibleItemCount = mLayoutManager.getChildCount();
                totalItemCount = mLayoutManager.getItemCount();
                pastVisiblesItems = mLayoutManager
                        .findFirstVisibleItemPosition();

                // Now check if userScrolled is true and also check if
                // the item is end then update recycler view and set
                // userScrolled to false
                if (userScrolled
                        && (visibleItemCount + pastVisiblesItems) == totalItemCount) {
                    userScrolled = false;

                    RefreshData(oldestPostId);
                }
            }
        });
}

这篇关于Firebase在滚动时动态加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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