I have a problem creating a custom window. The idea is to have a balloon that presents an image and some basic information about some location, with a link to another activity
with a greater detail.
The problem is that getLayoutInflater()
has the following error:
"Fragment.getLayoutInflater can only be called from within the same library group (groupId = com.android.support) "
MapFragment.java
import android.app.admin.SystemUpdatePolicy;
import android.content.Context;
import android.location.Criteria;
import android.location.LocationManager;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapaFragment extends SupportMapFragment implements OnMapReadyCallback {
private Context context;
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
SupportMapFragment mapFragment;
private GoogleMap mMap;
private LocationManager locationManager;
private static final String TAG = "MapaTag";
private String title[] = {"Medianeira - PR", "Pensao da Juraci"};
private String here = "Estou Aqui!";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker arg0) {
View v = getLayoutInflater().inflate(R.layout.inflate, null);
return v;
}
});
mMap = googleMap;
Marker marker;
//Location
LatLng medianeira = new LatLng(-25.295,-54.0939);
LatLng pensaoJuraci = new LatLng(-25.302268,-54.116805);
// Add a marker in Medianeira
mMap.addMarker(new MarkerOptions().position(medianeira).title(title[0]).snippet(here));
mMap.addMarker(new MarkerOptions().position(pensaoJuraci).title(title[1]).snippet(here));
// Move the camera to inicial location
mMap.moveCamera(CameraUpdateFactory.newLatLng(medianeira));
MarkerOptions options = new MarkerOptions();
try {
locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
mMap.setMyLocationEnabled(true);
Toast.makeText(getContext(), "Provider: "+provider, Toast.LENGTH_SHORT).show();
}catch (SecurityException ex){
Log.e(TAG, "ERROR", ex);
}
}
}