![](/img/trans.png)
[英]Sometimes listView.getChildAt(int index) returns NULL (Android)
[英]Android LinearLayoutManager#getChildAt(int) retuns null
我有這個代碼
public class CustomLinearLayoutManager extends LinearLayoutManager
{
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
{
super.onLayoutChildren(recycler, state);
int childCount = getChildCount();
View lastChild = getChildAt(childCount - 1);
// Do some stuff
}
}
出於某種原因,有時lastChild
為null
。 怎么可能?
正如評論中所提到的, lastChild
為null,因為根本沒有孩子,所以新的問題是為什么在調用super.onLayoutChildren(recycler, state);
之后沒有孩子super.onLayoutChildren(recycler, state);
?
似乎由於某種原因,沒有視圖使這種布局具有父級。 你可以發布你的xml嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.