How to convert below android method to recursive method?

I have created 800 snippets for educational software, so I cannot use vpPager.setOffscreenPageLimit(800)

. I think I should use a loop to open FragmentX(LessonX)

with buttons buttonclicks. My methods are below, I tried all of them and they are slow, opening fragmentXYZ

takes 3 minutes or 4 minutes. I want to help or want to try the recursive method, but I have no control over the conversion to the recursive method. Any help please? and sorry for my poor english.

public void  Mypagermethod_1(int x) {
    final ViewPager vpPager = (ViewPager) findViewById(R.id.pager);
    vpPager.setCurrentItem(0);
    int i;
    for (i = 1; i <= x; i++) {
        vpPager.setCurrentItem(vpPager.getCurrentItem() + 1);
    }
}

      

OR

public void  Mypagermethod2(int x) {
    final ViewPager vpPager = (ViewPager) findViewById(R.id.pager);
    vpPager.setCurrentItem(0);
    int i=1;
    while(i <= x){
        vpPager.setCurrentItem(vpPager.getCurrentItem() + 1);
        i++;
    }
}

      

OR

public void  Mypagermethod3(int x) {
    final ViewPager vpPager = (ViewPager) findViewById(R.id.pager);
    vpPager.setCurrentItem(0);
    int i=1;
    do {
        vpPager.setCurrentItem(vpPager.getCurrentItem() + 1);
        i++;
    } while(i <= x);
}

      

+3


source to share


2 answers


All of the above code examples will have the same performance and the transition to the recursive method is irrelevant. The problem is clearly around vpPager.setCurrentItem(vpPager.getCurrentItem() + 1);

, if this method is slow then it will be slow, but you call it.



You haven't provided enough information to allow a more specific answer, you need to debug and see where the time is running. Are you rendering images or something else that can be categorized as a separate thread?

0


source


Oh, I understand what you are doing. You don't need to simulate scrolling one page at a time in your method, just call vpPager.setCurrentItem (800).



+1


source







All Articles