Android : How I can show Google Maps V2 into a AlertDialog android

on Sunday, August 10, 2014


I have created an android application in that I want to show Google Maps V2 into a AlertDialog.


My code is:



LayoutInflater layoutInflater = LayoutInflater.from(getApplicationContext());

View promptView = layoutInflater.inflate(R.layout.prompt_mapview, null);

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
BasicProfileSetup.this);
alertDialogBuilder.setView(promptView);
alertDialogBuilder.setCancelable(false);

final AlertDialog alertD = alertDialogBuilder.create();


Button close = (Button) promptView.findViewById(R.id.btnClose_promptMapView);

// Some Code for initialize MAP

close.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
alertD.cancel();
}
});

alertD.show();


prompt_mapview.xml



<?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" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >

<Button
android:id="@+id/btnClose_promptMapView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Close" />

</LinearLayout>

<fragment
android:id="@+id/map_promptMapView"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>

</RelativeLayout>


In this code I gets the exception like:



android.view.InflateException: Binary XML file line #33: Error inflating class fragment


Any help would be appreciated!


Thanks.


0 comments:

Post a Comment