如何知道什么时候数据定制RecyclerView里面装的? [英] How to know when data is loaded inside custom RecyclerView?

查看:112
本文介绍了如何知道什么时候数据定制RecyclerView里面装的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建和我的应用程序使用自定义RecyclerView。我需要调用 getChildAt(0).getWidth()之前的任何努力拯救类领域的第一项宽度。为此,我需要捕捉时,适配器的数据加载(否则getChildAt(0)会返回null)。

I am create and using custom RecyclerView in my application. I need to call getChildAt(0).getWidth() before any working to save first item width in class field. For that I need to catch when data loading in adapter (otherwise getChildAt(0) will returns null).

如何定制RecyclerView里面搭上数据加载事件?

How to catch data loading event inside custom RecyclerView?

推荐答案

RecyclerView已经调用<一个href=\"https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#registerAdapterDataObserver(android.support.v7.widget.RecyclerView.AdapterDataObserver)\"相对=nofollow> registerAdapterDataObserver 和它的注销对应的适配器附带的适配器。

RecyclerView is already calling registerAdapterDataObserver and it's unregister counterpart on the adapter the supplied adapter.

这观察员有一些回调,让回收站知道什么时候数据添加,删除或更改。你应该好好利用这些优势。

This observer have several callbacks to let the Recycler know when data is added, removed or changed. You should take advantage of those.

此外,当下适配器更改数据,它不是在屏幕上创建视图的同一时刻/布局。您可能需要调用 getViewTreeObserver()。addOnGlobalLayoutListener 来接收的时候,孩子已经布局在屏幕上的回调。

Also, the moment the adapter changes the data, it's not the same moment the views are created/layout on the screen. You might have to call getViewTreeObserver().addOnGlobalLayoutListener to receive a callback when the children have been layout on the screen.

希望它能帮助,快乐编码。

Hope it helps, happy coding.

这篇关于如何知道什么时候数据定制RecyclerView里面装的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆