I am beginner in programming and I've tried to implement the google maps inside sliding menu, at home, this is the fragment

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.moictab.decanias.MapActivity$PlaceholderFragment" >

<fragment 

          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"

          />

</RelativeLayout>

This is the class I want to put the maps

public class HomeFragment extends Fragment {

    public HomeFragment(){}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_home, container, false);

        android.app.FragmentTransaction mTransaction = getFragmentManager().beginTransaction();
        SupportMapFragment mFRaFragment = new MapFragment();
        Bundle args = new Bundle();
        args.putDouble("lat", -4.573362);
        args.putDouble("lng", -44.6020426);
        mFRaFragment.setArguments(args);
        mTransaction.add(R.id.map, mFRaFragment);
        mTransaction.commit();


        MapsInitializer.initialize(getApplicationContext());


        return rootView;
    }

}

But I am getting these errors

mTransaction.add(R.id.map, mFRaFragment);

The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, SupportMapFragment)

MapsInitializer.initialize(getApplicationContext());

The method getApplicationContext() is undefined for the type HomeFragment

The solution would be:

public class HomeFragment extends FragmentActivity {

And everything stay okay in this class, but in MainActivity is not acceptable because there is extends Fragment, I already tried to change there to FragmentActivity, but the the replace doesn't work:

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, fragment).commit();

message: "The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, FragmentActivity)"

I already tried to use android.support.v4.app.Fragment, but it doesn't work too. My problem is to implement the google maps android in navigation Drawer.

/**
 * Diplaying fragment view for selected nav drawer list item
 * */
private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch (position) {
    case 0:
        fragment = new HomeFragment();
        break;
    case 1:
        fragment = new FindPeopleFragment();
        break;
    case 2:
        fragment = new PhotosFragment();
        break;
    case 3:
        fragment = new CommunityFragment();
        break;
    case 4:
        fragment = new PagesFragment();
        break;
    case 5:
        fragment = new WhatsHotFragment();
        break;

    default:
        break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    } else {
        // error in creating fragment
        Log.e("MainActivity", "Error in creating fragment");
    }
}

I have seen too many ways to do, but they don't work.

Related posts

Recent Viewed