当我开始我的活动时,我想展示我的教程,因此我需要等待RecyclerView
准备就绪,在我的用例中,我希望前4个项目准备就绪。我试过以下:
GridLayoutManager glm = new GridLayoutManager(this, Tools.isScreenLandscape(this) ? 3 : 2, GridLayoutManager.VERTICAL, false)
{
boolean mTutorialHandled = false;
@Override
public void onLayoutChildren(final RecyclerView.Recycler recycler, final RecyclerView.State state)
{
super.onLayoutChildren(recycler, state);
// make sure, at least the first 4 views are ready
if (!mTutorialHandled)
{
boolean allViewsReady = true;
for (int i = 0; i < 4; i++)
allViewsReady &= recycler.getViewForPosition(i) != null;
if (allViewsReady)
{
TutorialManager.checkTutorial(false, savedInstanceState, MainActivity.this, mBinding);
mTutorialHandled = true;
}
}
}
};
但这不起作用。任何人都知道如何知道RecyclerView
的前n个视图何时准备就绪?