这是我的xml代码 dialogFragment.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "this is map"/>
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
这是我的JAVA代码:
public class myDialog extends DialogFragment implements OnClickListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
getDialog().setTitle("Title");
View v = inflater.inflate(R.layout.dialogFragment.xml, null);
return v;
}
public void onClick(View arg0) {
}
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
}
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
}
}
当我第一次测试此代码时,我打开对话框,它与地图完美配合,但当我点击后退按钮并再次打开按钮时,它停止工作。但是当我删除地图时它工作正常(从不显示错误)。 因此,请帮助我使对话框片段无错误地使用地图,非常感谢您提前。
这是错误日志:
04-06 15:15:57.434:E / AndroidRuntime(13393):致命异常:主要 04-06 15:15:57.434:E / AndroidRuntime(13393):流程: com.example.newapp,PID:11391 04-06 15:15:57.434: E / AndroidRuntime(13393):android.view.InflateException:二进制XML 文件行#86:错误膨胀类片段04-06 15:15:57.434: E / AndroidRuntime(13393):at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) 04-06 15:15:57.434:E / AndroidRuntime(13393):at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.view.LayoutInflater.inflate(LayoutInflater.java:492)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.view.LayoutInflater.inflate(LayoutInflater.java:397)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.view.LayoutInflater.inflate(LayoutInflater.java:353)04-06 15:15:57.434:E / AndroidRuntime(13393):at com.example.newapp.ReqDialog.onCreateView(myDialog.java:16)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.app.Fragment.performCreateView(Fragment.java:1700)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890) 04-06 15:15:57.434:E / AndroidRuntime(13393):at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062) 04-06 15:15:57.434:E / AndroidRuntime(13393):at android.app.BackStackRecord.run(BackStackRecord.java:684)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) 04-06 15:15:57.434:E / AndroidRuntime(13393):at android.app.FragmentManagerImpl $ 1.run(FragmentManager.java:443)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.os.Handler.handleCallback(Handler.java:733)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.os.Handler.dispatchMessage(Handler.java:95)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.os.Looper.loop(Looper.java:136)04-06 15:15:57.434: E / AndroidRuntime(13393):at android.app.ActivityThread.main(ActivityThread.java:5017)04-06 15:15:57.434:E / AndroidRuntime(13393):at java.lang.reflect.Method.invokeNative(Native Method)04-06 15:15:57.434:E / AndroidRuntime(13393):at java.lang.reflect.Method.invoke(Method.java:515)04-06 15:15:57.434: E / AndroidRuntime(13393):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779) 04-06 15:15:57.434:E / AndroidRuntime(13393):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)04-06 15:15:57.434:E / AndroidRuntime(13393):at dalvik.system.NativeStart.main(Native Method)04-06 15:15:57.434: E / AndroidRuntime(13393):引起: java.lang.IllegalArgumentException:二进制XML文件行#86: 重复ID为0x7f050079,标记为null或父ID为0xffffffff com.google.android.gms.maps.MapFragment 04-06的另一个片段 15:15:57.434:E / AndroidRuntime(13393):at android.app.Activity.onCreateView(Activity.java:4791)04-06 15:15:57.434:E / AndroidRuntime(13393):at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689) 04-06 15:15:57.434:E / AndroidRuntime(13393):
[... 20更多]
答案 0 :(得分:0)
试试此代码:https://github.com/yurevich1/habrtimezone/blob/master/res/layout/agmap.xml#L6
我认为你在档案中写错了标题。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
我希望它对你有用。