1

I would like to implement an infowindow with a radio group, in which I could select the options.

My code:

public class PontosFragment extends Fragment {

@SuppressLint("NewApi")
  public View onCreateView(final LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {


if (container == null) {
  return null;
}   

View v =  (RelativeLayout) inflater.inflate(R.layout.fragment_pontos, container, false);

final GoogleMap map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

  LatLng CampoMourao = new LatLng(-24.046817,-52.379597);
  map.setMyLocationEnabled(true);
  map.moveCamera(CameraUpdateFactory.newLatLngZoom(CampoMourao, 15)); //


  MarkerOptions options = new MarkerOptions();
  options.position(CampoMourao);
  options.icon(BitmapDescriptorFactory.fromResource
        (R.drawable.ic_launcher));
  map.addMarker(options);    

  map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() 
  {


    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) 
    {
        View v = inflater.inflate(R.layout.infowindow, null);

        return v;
    }
});

return v;

}

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Irmãos Pereira"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RadioButton
        android:id="@+id/radio0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="RadioButton" />

    <RadioButton
        android:id="@+id/radio1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />

    <RadioButton
        android:id="@+id/radio2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" />
</RadioGroup>

Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77

1 Answers1

0

Google Maps Info Windows are not "live" views. They are just rendered as a bitmap and then displayed, so they are not interactive.

One option is to display the View yourself (via GoogleMap.setOnMarkerClickListener() instead of using an InfoWindowAdapter). But in that case you are responsible for moving the view then the map is scrolled.

That said, there are hacks to enable (somewhat limited) interaction. See this answer, for example.

Community
  • 1
  • 1
matiash
  • 54,791
  • 16
  • 125
  • 154