how to use maps fragment in navigation drawer?

拈花ヽ惹草 提交于 2020-01-08 03:32:25

问题


how to use fragment maps in navigation drawer? I am trying to use but the error, so I possessed three chronological list that contains the display maps, I created two more yet or is empty. when I opened the first road maps well after I select the list view both appear blank activity was not a problem, and when I want to go back to the case where the application maps directly out ..

public class CreateFragment extends Fragment {
	
	
	public CreateFragment() {
		
	   
		
		
	}

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

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

		return rootView;
	}

}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/fragment1"
        android:name="com.google.android.gms.maps.MapFragment"
       
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

</RelativeLayout>

![my LogCat][1]


    10-16 12:16:46.080: E/dalvikvm(1007): Could not find class 'gpq', referenced from method gpr.a
10-16 12:16:46.090: E/dalvikvm(1007): Could not find class 'gpq', referenced from method gpr.a
10-16 12:16:46.090: E/dalvikvm(1007): Could not find class 'gpq', referenced from method gpr.a
10-16 12:16:48.980: E/dalvikvm(1007): Could not find class 'com.google.android.gms.location.internal.ParcelableGeofence', referenced from method gls.a
10-16 12:17:06.290: E/AndroidRuntime(1007): FATAL EXCEPTION: main
10-16 12:17:06.290: E/AndroidRuntime(1007): Process: com.Zen.gethere, PID: 1007
10-16 12:17:06.290: E/AndroidRuntime(1007): android.view.InflateException: Binary XML file line #6: Error inflating class fragment
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at com.Zen.gethere.CreateFragment.onCreateView(CreateFragment.java:43)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.app.Fragment.performCreateView(Fragment.java:1700)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.app.BackStackRecord.run(BackStackRecord.java:684)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.os.Handler.handleCallback(Handler.java:733)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.os.Handler.dispatchMessage(Handler.java:95)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.os.Looper.loop(Looper.java:136)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at java.lang.reflect.Method.invokeNative(Native Method)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at java.lang.reflect.Method.invoke(Method.java:515)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at dalvik.system.NativeStart.main(Native Method)
10-16 12:17:06.290: E/AndroidRuntime(1007): Caused by: java.lang.IllegalArgumentException: Binary XML file line #6: Duplicate id 0x7f080051, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.app.Activity.onCreateView(Activity.java:4791)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
10-16 12:17:06.290: E/AndroidRuntime(1007): 	... 19 more
enter code here

回答1:


You could try calling a method like OpenMap() from your navigation drawer in this section, where the method is located in your main activity with the following code:

public void onSectionAttached(int number) {
        switch (number) {
            case 1:
                mTitle = getString(R.string.title_section1);
                OpenMap();
                break;




private void openMap() {
        double latitude = 32.715000;
        double longitude = -117.162500;
        String label = "Starting point";
        String uriBegin = "geo:" + latitude + "," + longitude;
        String query = latitude + "," + longitude + "(" + label + ")";
        String encodedQuery = Uri.encode(query);
        String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
        Uri uri = Uri.parse(uriString);
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
        startActivity(intent);


来源:https://stackoverflow.com/questions/26400653/how-to-use-maps-fragment-in-navigation-drawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!