I have a ViewPager, and I'd like to get the current selected and visible view, not a position.
getChildAt(getCurrentItem)
returns wrong View
This works not all the time. Sometimes returns null, sometimes just returns wrong View.
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser == true) {
mFocusedListView = ListView;
}
}
PageListener on ViewPager
with getChildAt()
also not working, not giving me the correct View every time.
How can i get current visible View?
View view = MyActivity.mViewPager.getChildAt(MyActivity.mViewPager.getCurrentItem()).getRootView();
ListView listview = (ListView) view.findViewById(R.id.ListViewItems);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…