2

我错过了一些东西。我分层了几个 ExpandableGroup 项目,前两层工作正常,但是当我尝试访问第三层时,什么也没有发生。我查看了调试器,收集了这些项目,但它们没有出现在视图中。如果我将它们放在section.add最外面的 ExpandableGroup 中,它们就会出现,但它们应该在最外面的组中,如果我将该组添加到其他任何地方,它会在列表底部添加另一个组,它应该这样做。

我正在寻找的是

Item
    SubItem
       SubSubItem <- This one is a clickable item, which works if it's added to the Item group. 

class Stores : AppCompatActivity() {
    private lateinit var userListenerRegistration: ListenerRegistration
    private var shouldInitCategoryRecyclerView = true

    private val groupAdapter = GroupAdapter<GroupieViewHolder>()

    private var storeSection = Section()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_stores)

        userListenerRegistration =
            FirestoreUtil.addCategoryListener(this::updateCategoryRecyclerView)
    }

    override fun onDestroy() {
        super.onDestroy()
        FirestoreUtil.removeListener(userListenerRegistration)
        shouldInitCategoryRecyclerView = true
    }


    private fun updateCategoryRecyclerView(items: List<Item>) {

        fun init() {
            recycler_view_categories.apply {
                layoutManager = LinearLayoutManager(this@Stores)
                adapter = groupAdapter.apply {
                    setOnItemClickListener(onItemClick)
                }
            }

            for (item in items) {
                if (item is CategoryItem) {
                    ExpandableGroup(item, false).apply {

                        userListenerRegistration =
                            FirestoreUtil.addSubCategoriesListener(
                                item.category.categoryName
                            ) { subCategories ->
                                for (subCategory in subCategories) {
                                    if (subCategory is SubCategoryItem) {
                                        add(Section(subCategory))
                                        ExpandableGroup(subCategory, false).apply {

                                            userListenerRegistration =
                                                FirestoreUtil.addStoreListener(
                                                    item.category.categoryName,
                                                    subCategory.subCategory.subCategoryName,
                                                    this@Stores
                                                ) { stores ->
                                                    for (store in stores) {
                                                        if (store is StoreItem) {
                                                            add(Section(store))
                                                        }
                                                    }
                                                }
                                        }
                                    }
                                }
                            }
                        groupAdapter.add(this)
                    }
                }
            }
            shouldInitCategoryRecyclerView = false
        }

        fun updateItems() = storeSection.update(items)

        if (shouldInitCategoryRecyclerView)
            init()
        else
            updateItems()
    }

    private val onItemClick = OnItemClickListener { item, view ->
        if (item is StoreItem) {
            Toast.makeText(this, item.store.storeName, Toast.LENGTH_SHORT).show()
        }
    }


}

调用,FirestoreUtil从 Firestore 获取数据并显示它,我让它像我想要的那样工作,但是最后一次调用 stores没有返回应用程序中可见的值。它似乎得到了数据,但它不显示它。这就是视图的样子 第二个有一个突出显示的蓝色项目。 这应该会触发它显示商店,但它不会

4

0 回答 0