lacas lacas - 27 days ago 19
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
    View


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(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
    ViewPager
    with
    getChildAt()
    , 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(R.id.ListViewItems);

Answer

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

Comments