lundi 25 mai 2015

Android 2.3 Scroll Not Working on Viewpager in fragment of main Viewpager

There is main ViewPager in my application with 5 tabs. each tab has one Fragment which has ListView as well. I've seen similar issues at StackOverflow (here, here)

So ListView has various views and some of views have also ViewPager for recommending account and any contents such as facebook and other apps.

By the way, horizontal scrolling doesn't work in Gingerbread version (android 2.3). Anyway upper gingerbread, it works well.

One more thing is scrolling of main ViewPager is working, so what I though is I have to deliver my touch event to child ViewPager, not to parent ViewPager.

I tried below codes in my ViewPager, but not working. and also I tried this too but not working.

@Override
    try {
        //Handle the issue only in lower versions of android
        if (Util.isGingerbreadAndLower()) {
            ViewPager viewPager = (ViewPager) v;
            int currentPage = viewPager.getCurrentItem();
            int size = viewPager.getAdapter().getCount();
            //if ViewPager has reached its end and if user tries to swipe left allow the parent to scroll
            if (currentPage == (size - 1) && dx < 0) {
                return false;
            }
            //if ViewPager has reached its start and if user tries to swipe right allow the parent to scroll
            else if (currentPage == 0 && dx > 0) {
                return false;
            }
            //Allow the child to scroll hence blocking parent scroll
            else {
                return true;
            }
        }
        return super.canScroll(v, checkV, dx, x, y);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

Any idea to solve this problem?

Aucun commentaire:

Enregistrer un commentaire