我有一个AlertDialog,用于打开具有特定坐标的地图。 它首先运行不正常。 但是从第二次出现以下错误:
android.view.InflateException: Binary XML file line #32: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.prodados.comcenter.activity.VendaActivity.popupLocaGPSCliente(VendaActivity.java:999)
at com.prodados.comcenter.activity.VendaActivity.access$23(VendaActivity.java:986)
at com.prodados.comcenter.activity.VendaActivity$8.onItemClick(VendaActivity.java:464)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1510)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3339)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #32: Duplicate id 0x7f09004e, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
at android.app.Activity.onCreateView(Activity.java:4971)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
布局文件:cliente_local.xml
<fragment
android:id="@+id/fragment1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp" />
调用AlertDialog的方法方法:
private GoogleMap mapa;
private void popupLocaGPSCliente1(){
try {
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = VendaActivity.this;
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = vi.inflate(R.layout.cliente_local, null);
LatLng cordGoogleSp = new LatLng(latitude, longitude);
mapa = ((MapFragment) getFragmentManager().findFragmentById(R.id.fragment1)).getMap();
mapa.clear();
mapa.addMarker(new MarkerOptions().position(cordGoogleSp));
CameraPosition update = new CameraPosition(cordGoogleSp, 15, 0, 0);
mapa.animateCamera(CameraUpdateFactory.newCameraPosition(update), 5000, null);
mapa.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
builder = new AlertDialog.Builder(mContext);
builder.setView(view);
builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog = builder.create();
alertDialog.setIcon(R.drawable.ico_cliente_local);
alertDialog.setTitle("Localização do Cliente:");
alertDialog.show();
} catch (Exception e) {
exibirMensagem("Erro: ", e.toString());
e.printStackTrace();
}
}
答案 0 :(得分:0)
您的MapFragment
(fragment1)
课程没有通过SupportMapFragment
android:name="com.google.android.gms.maps.SupportMapFragment"
内部活动
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mapFragment = (SupportMapFragment) myFragmentManager
.findFragmentById(R.id.fragment1);
mapa = mapFragment.getMap();