lacas lacas - 9 months ago 115
Android Question

Android ViewPager get the current View

I have a ViewPager, and I'd like to get the current selected and VISIBLE VIEW, not just a NUMBER.

  1. getChildAt(getCurrentItem)
    returns wrong

    public void setUserVisibleHint(boolean isVisibleToUser) {

    if (isVisibleToUser == true) {
    mFocusedListView = ListView;

  2. this is the second code, this is not working all the time sadly. sometimes returns null, sometimes just returns wrong View

  3. pageListener on
    , also not working, not giving me the correct View every time.

How I want to get back the current visible View?

view = MyActivity.mViewPager.getChildAt(MyActivity.mViewPager.getCurrentItem()).getRootView();
listview = (ListView) view.findViewById(;

Answer Source

OK I figure it out, I just add with setTag a name to all Views/ListViews, and just calling findViewWithTag(mytag), so no other way to do this, at the moment.

Thanks Leslie