Reputation: 343
This method getSupportFragmentManager()
belongs to FragmentActivity
,
how can I replace this method, if I used only extends Fragment
?
I get this error
Error:(30, 42) error: cannot find symbol method getSupportFragmentManager()
using this code in public class MapsFragment extends FragmentActivity
:
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_maps,container, false);
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.addMarker(new MarkerOptions().position(new LatLng(57.70, 11.96)).title("Marker"));
}
}
Upvotes: 0
Views: 3528
Reputation: 61
If you want to access the fragment manager from a Fragment, even from the support library, you should use the getFragmentManager() method.
http://developer.android.com/reference/android/app/Fragment.html#getFragmentManager()
http://developer.android.com/reference/android/support/v4/app/Fragment.html#getFragmentManager()
Upvotes: 0
Reputation: 338
use
mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
instead of
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
Upvotes: 1