【问题标题】:FirebaseListAdapter, How to update individual list views after populateViewFirebaseListAdapter,如何在 populateView 之后更新单个列表视图
【发布时间】:2017-11-07 17:00:37
【问题描述】:

我已经实现了一个 firebase 列表适配器来加载项目列表(列表 A)。我的数据结构设置为在列表 A 中,每个项目还包含对位于数据库中其他位置 (isNice) 的某些信息的引用 id。同样:

ListA
- ObjA
  - title : "hi"
  - id : "ObjAid"

isNice
- ObjAid : "true"

我目前正在使用另一个数据库操作来查找“isNice”子项中的 id,传递“ObjAid”、列表位置,然后是 resultReceiver 以获取结果。 我的问题是,当 resultReceiver 得到一个 resultData(值为“true”)时,我不知道如何修改 firebase 列表中特定位置的数据。

我过去的经验是使用将我的数据加载到我自己的 ArrayList 并为 listView 创建一个自定义适配器,在这种情况下,我可以在加载额外信息时轻松更新填充的视图。我想暂时避免设置自己的 ArrayList 来存储数据,有利于 FirebaseListAdapter 的简单性。感谢所有提示,谢谢 :)

【问题讨论】:

    标签: android firebase firebase-realtime-database firebaseui


    【解决方案1】:

    经过反复试验,我选择了 RecyclerView + FirebaseRecyclerViewAdapter 方法。从长远来看,使用回收器也更好,在我的用例中,列表可以达到 3K+。使用 RecyclerView.findViewHolderForAdapterPosition() 我同样可以在从结果接收器获取数据后引用特定的 itemView:

    // Reference the Item's view at the specific position
    myViewHolder itemViewHolder = recyclerView.findViewHolderForAdapterPosition(position);
    // Reference and set the views and here......
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多