CardStackView icon indicating copy to clipboard operation
CardStackView copied to clipboard

onCardAppeared() not called first time when items are loaded

Open asifrpatel opened this issue 6 years ago • 6 comments

When items are loaded, then onCardAppeared() is not called for position 0.

asifrpatel avatar Jun 20 '19 06:06 asifrpatel

I have the same problem. Can this be looked at?

szili9992 avatar Jul 24 '19 07:07 szili9992

This happened to me when I firstly passed empty list to adapter, and then passed not empty list. Now my code looks: if (items.isNotEmpty) { adapter.setItems(items) adapter.notifyDataSetChanged() }

robertBadamshin avatar Aug 15 '19 10:08 robertBadamshin

is there any workaround?

dbof10 avatar Dec 04 '19 13:12 dbof10

my case I tried

override fun submitList(list: List<Swipe>?) {
        if (!firstCommit) {
            super.submitList(list) {
                notifyDataSetChanged()
            }
            firstCommit = true
        } else {
            super.submitList(list)
        }
    }

note that
val holder = vStackView.findViewHolderForAdapterPosition(position) holder is null in this particular case

dbof10 avatar Dec 04 '19 14:12 dbof10

This happens because s.didStructureChange() returns false or getTopView() returns null. It returns false or null on some cases, for example: your adapter has empty data list and you try push new data with DiffUtil. In this case notifyDataSetChanged will not be called. For prevent this behavior add some check (for ex: YourAdapter#data.isEmpty()) before using DiffUtil and if your current adapter data is empty — use common way with notifyDataSetChanged instead of DiffUtil.

TemMax avatar Apr 23 '20 12:04 TemMax

my case I tried

override fun submitList(list: List<Swipe>?) {
        if (!firstCommit) {
            super.submitList(list) {
                notifyDataSetChanged()
            }
            firstCommit = true
        } else {
            super.submitList(list)
        }
    }

note that val holder = vStackView.findViewHolderForAdapterPosition(position) holder is null in this particular case

This helped me..Thanks..

AnSuSh avatar Apr 20 '22 15:04 AnSuSh