I am trying to get to the application from my static class but get this error
The method getActivity() is undefined for the type PniemActivity.MyFragmentAdapter
But when i leave getActivity() out i get this message:
Cannot make a static reference to the non-static method getApplication() from the type Activity
This is my code.
private static class MyFragmentAdapter extends FragmentPagerAdapter{
private final int NUM_OF_PAGES = 10;
public MyFragmentAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int index){
return PageFragment.newInstance("Hoi "+ index );
}
@Override
public int getCount(){
appData = ((myApp) getActivity().getApplication()).slaughterData;
return NUM_OF_PAGES;
}
}
I want to get the amount of fragments needed from my database and that is why i want to get access to my application.
Any ideas?
Thanks
As far as I can tell getActivity() is a method on Fragment, not on FragmentPageAdapter. You could get the current Fragment from the FragmentManager (which you have a reference to), but I would probably do as Vladimir suggests in the comment: