我有一个 ViewPager,我想得到当前选定的和可见的视图,而不是一个位置。
View
这并不总是有效。有时返回 null,有时只是返回错误的视图。
@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);