Подскажите, пожалуйста, почему findLastVisibleItemPosition() возвращает -1
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_photo_gallery, container, false);
mPhotoRecyclerView = (RecyclerView) v.findViewById(R.id.photo_recycler_view);
mPhotoRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 3));
...
setupAdapter();
return v;
}
private void setupAdapter() {
if (isAdded()) {
if (mPhotoRecyclerView.getAdapter() == null ) {
mPhotoRecyclerView.setAdapter(new PhotoAdapter(mItems));
mLastVisibleItemPosition = ((GridLayoutManager)mPhotoRecyclerView
.getLayoutManager()).findLastVisibleItemPosition();
Log.i(TAG, "Последний видимый элемент: " + String.valueOf(mLastVisibleItemPosition));
} else {
mPhotoRecyclerView.getAdapter().notifyDataSetChanged();
}
}
}
Сборка персонального компьютера от Artline: умный выбор для современных пользователей