0

So I've searched allot, and after more in depth and reading, I got the ViewPager to work using this answer - How to implement a ViewPager with different Fragments / Layouts But now I cannot link it to my existing layouts.

I already used MainActivity and it has code that displays the time and stuff so I just made the ViewPager activity called Launch activity but within it, you an set the pages to scroll to, like this -

@Override
public Fragment getItem(int pos) {
    switch(pos) {

    case 0: return FirstFragment.newInstance("FirstFragment, Instance 1");
    case 1: return SecondFragment.newInstance("SecondFragment, Instance 1");
    case 2: return ThirdFragment.newInstance("ThirdFragment, Instance 1");
    case 3: return ThirdFragment.newInstance("ThirdFragment, Instance 2");
    case 4: return ThirdFragment.newInstance("ThirdFragment, Instance 3");
    default: return ThirdFragment.newInstance("ThirdFragment, Default");
    }
}

But when I change FirstFragment or any of the return states to my pre made classes, it doesn't work. Is there anything I have to do to get it to work?

Explained, furthermore.

So I have my application already set up, but I wish to have it better laid out and more organised, instead of having to scroll a billion times. So I would like to link to my ViewPager to all my activities so I can swipe amongst them. But the problem comes upon adding the class (Activity) to the fragments section (Code above). I simply cannot add it to the section. when I do it gives me an error and tells me this - The method newInstance(String) is undefined for the type MainActivity. so I clicked create method, but I dont know what to do in there, all I want to do is simply link my class that contains functions to my viewpager.

Community
  • 1
  • 1
Robin
  • 577
  • 1
  • 7
  • 13
  • Your question and explanations are not very clear. Could you please improve them? – L. G. May 19 '14 at 11:05
  • show the code you are talking about. It sounds like you are trying to add an activity to your viewpager, but its supposed to only hold fragments, not activities, – Daniel Bo May 19 '14 at 12:23
  • @DanielBo You are correct, I just found out that viewpager only works with fragments, so how am I supposed to get viewpager to work? – Robin May 19 '14 at 12:34
  • you could just move your code from an activity into a fragment? – Daniel Bo May 20 '14 at 07:37
  • That didn't work, I ended up converting the Activity into a fragment then used getView and getActivity to fix some errors. – Robin May 21 '14 at 05:37

0 Answers0