0
I have a problem joining Navigation Drawer as Google Maps. I want google to be my home page and I want it to be on the Navigation Drawer list as an item, but there’s been a little snag. I’ll try to explain it the best way and hope you help me.
In the Class of MainFragment
(Google Maps Code) asks me to import android.app.Fragment
but when I go to MainActivity
asks that in class MainFragment
be imported android.support.v4.app.Fragment
Main Fragment
public class MainFragment extends Fragment implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_main, container,false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.map);
fragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng marker = new LatLng(-33.867, 151.206);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(marker, 13));
googleMap.addMarker(new MarkerOptions().title("Hello Google Maps!").position(marker));
}
With the android.app.Fragment
there is no mistake, but when I care android.support.v4.app.Fragment
the error happens in (MapFragment)getChildFragmentManager().findFragmentById(R.id.map);
Mainactivity
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
NavigationView navigationView = null;
Toolbar toolbar = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Set the fragment initially
MainFragment fragment = new MainFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
Import android.support.v4.app.Fragment
in MainFragment
to MainActivity
no mistake, but care android.app.Fragment
the error occurs in (where it is in bold):
fragmentTransaction.replace(R.id.fragment_container, Fragment);
Basically on each side they ask for different imports, I know I understand where the mistake is, but I don’t know how to fix it.
Lari, could you post the error stacktrace? This would help in solving your problem
– Rubico
Care
android.support.v4.app.Fragment
so much atMainFragment
as inMainActivity
doesn’t work?– ramaral