Find out when the recyclerview project will be presented for the first time (Android)

I'm trying to use Google Analytics enhanced e-commerce to send "show times" of my products on recyclerview staggeredgrid. Every time a user scrolls, I check which products are visible and send hits:

public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
        for (int i = firstVisibleItemPosition; i <= lastVisibleItemPosition; i++) {
            Offer offer = mListViewContentFetcher.getApiObjects().get(i);

            Product product = new Product()
                .setId(offer.getCode())
                .setName(offer.getTitle())
                .setCategory(offer.getStore().getName())
                .setPosition(i);

            builder.addImpression(product, "products_list");
        }

        mTracker.setScreenName("Products List");
        mTracker.send(builder.build());
    }
}

But when I build recyclerview for the first time and the first products are visible, I still need to run it

How do I know the first item is ready? I tried to use viewtreeobserver on recyclerview and onbindviewholder, but failed

Edit: This is inside the clip used on the viewpager, so I need to know when the project is really visible, not just add

thank you

resolvent:

Can't you use the onviewattachedtowindow and onviewdetachedfromwindow methods of recyclerview.adapter to track when things enter / leave the view?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>