My MainActivity
has a double
latitude value that I would like to pass to a fragment inside a FragmentPagerAdapter
, so I created this getter method in MainActivity.java
:
public double getLatitude() {
return this.latitude;
}
Now I am trying to pass this value to a fragment when I create it (the getItem()
method is part of a FragmentPagerAdapter
class):
public Fragment getItem(int position) {
if (position == 0) {
return new Fragment1();
} else if (position == 1) {
return new Fragment2();
} else {
Fragment3 fragment3 = new Fragment3();
Bundle args = new Bundle();
args.putDouble(fragment3.ARG_PARAM1, getActivity().getLatitude());
fragment3.setArguments(args);
return fragment3;
}
}
However, I get a compilation error that says Error:(156, 68) error: cannot find symbol method getActivity()
.
How can I get my main activity's getLatitude()
when I create a new instance of a fragment?