내 활동이 LinearLayoutManager
인 RecyclerView
을 보여줍니다. 목록의 첫 번째 항목 (View
)을 가져오고 싶습니다. this post's accepted answer에 따르면, 내가 LinearLayoutManager.findViewByPosition()
메서드를 호출 할 수 있지만, 대신 null
이 표시됩니다. 왜?LinearLayoutManager.findViewByPosition()가 null을 반환합니다.
RecyclerView list = findViewById(R.id.list);
LinearLayoutManager llm = new LinearLayoutManager(this);
list.setLayoutManager(llm);
MyAdapter adapter = new MyAdapter();
list.setAdapter(adapter);
View firstViewItem = llm.findViewByPosition(0); // <-- null
adapter
에는 항목이 포함되어 있지만 비어 있지 않습니다.
답변 해 주셔서 감사합니다. 그 사건을 어떻게들을 수 있니? –
Otto Event Bus와 같은 것을 사용할 수 있습니다. 그것은 좋은 이벤트 lib를 사용할 수 있습니다. 웹에서 몇 가지 예를 찾을 수 있습니다. 가능한 경우 어디서나 이벤트 접근 방식을 사용하는 것이 좋습니다. 성능 향상에 도움이되며 명확한 코드를 작성하는 데 도움이됩니다. – firegloves
하지만 RecyclerView가 언제 채워 졌는지 어떻게 알 수 있습니까? –