我正在编写一个类来显示SupportMapFragment
a DialogFragment
,如图所示。问题是我收到一个错误“Inflating class fragment”,尽管已经导入了import com.google.android.gms.maps.SupportMapFragment;
.
布局/mapa.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="vertical" >
<fragment android:id="@+mapa/mapa" android:layout_width="match_parent" android:layout_height="300dp" class="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>
班级:
package br.com.globalinterativa.uteis;
import br.com.globalinterativa.rcf.R;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.model.LatLng;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import com.google.android.gms.maps.SupportMapFragment;
import android.view.LayoutInflater;
public class SupMapFragmentDF extends DialogFragment implements OnMapClickListener, OnMapLongClickListener {
private LatLng latLong;
private int actionCode;
private CallBackMethods returnn;
public SupMapFragmentDF(CallBackMethods returnn, int actionCode){
this.returnn = returnn;
this.actionCode=actionCode;
}
public interface CallBackMethods {
public abstract void onLatLongSetados(LatLng latLong, int actionCode);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
returnn.onLatLongSetados(latLong, actionCode);
}
});
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.mapa, null) );
return builder.create();
}
public static void inicializa(DatePickerDialogFragment dp, Bundle b, FragmentManager fm) {
}
@Override
public void onMapLongClick(LatLng latLng) {
this.latLong = latLong;
}
@Override
public void onMapClick(LatLng latLng) {
this.latLong = latLong;
}
}