代码之家  ›  专栏  ›  技术社区  ›  Adarsh Binjola

如何在Android中添加FireStore分页

  •  0
  • Adarsh Binjola  · 技术社区  · 7 年前

    请帮助我,我需要在Android FireStore中添加分页,我已经使用基本适配器从FireBase获取事件。我读过医生没有找到解决办法。

       DocumentSnapshot lastVisible = documentSnapshots.getDocuments()
                .get(documentSnapshots.size() -1);
    
        // Construct a new query starting at this document,
        // get the next 25 cities.
        Query next = db.collection("cities")
                .orderBy("population")
                .startAfter(lastVisible)
                .limit(25);
    
        // Use the query for pagination
        // ...
    

    我想要的是获取下一个数据并将其添加到我的同一个列表中,我还想要在其中添加事件侦听器并在列表底部添加数据。 如何为同一个侦听器调用下一个查询,以便在运行时更改数据。 事先谢谢。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Alex Mamo    7 年前

    This 最简单的方法是使用 ListView ArrayAdapter 单击按钮。更复杂的方法可以在 this RecyclerView

    startAfter() 方法。因此,可以通过将查询光标与limit()方法组合在一起对查询进行分页。您需要使用批处理中的最后一个文档作为下一批的光标的开始。

    video 为了更好的理解。