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, like this as well:
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
and also import
import android.support.v4.app.FragmentActivity; Before you do this Right click project->properties->buildpath->java build path -> libraries .. then click on add external jars
the go to
\android-sdks\extras\android\support\v4
and select android-support-v4.jar
As been stated by the error you receive:
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4452000 but found 0. You must have the following declaration within the element:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
So you need to add this meta-data element to you Manifest file under the application hive:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句