I'm using a custom InfoWindowAdapter in order to use my Marker InfoWindow layout, with my data. Each Marker object has associated an AnimalMarker object (stored in a HashMap)
The Checkboxes however won't update , even though there is no error printed and the Log.d(..) prints the boolean that should be in the checkbox.
Is there something that I'm doing wrong or that I'm not aware of regarding CheckBoxes inside InfoWindows?
code inside my MapActivity
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
View view = getLayoutInflater().inflate(R.layout.marker_info_window, null);
AnimalMarker animalMarker = allMarkersHashMap.get(marker);
if (animalMarker == null) {
animalMarker = myMarkersHashMap.get(marker);
}
Log.d(TAG, "getInfoWindow: animalMarker --> " + animalMarker);
TextView miwLocation = (TextView) view.findViewById(R.id.miwLocation);
TextView miwAnimalName = (TextView) view.findViewById(R.id.miwAnimalName);
TextView miwAnimalAge = (TextView) view.findViewById(R.id.miwAnimalAge);
ImageView miwImage = (ImageView) view.findViewById(R.id.miwImage);
CheckBox miwAdultCB = (CheckBox) view.findViewById(R.id.miwAdultCB);
CheckBox miwNeuteredCB = (CheckBox) view.findViewById(R.id.miwNeuteredCB);
miwLocation.setText(marker.getTitle());
miwAnimalName.setText(animalMarker.getAnimal().getAnimalName());
miwAnimalAge.setText(animalMarker.getAnimal().getAproxAge().toString() + " yrs");
miwAdultCB.setChecked(animalMarker.getAnimal().isAdult());
Log.d(TAG, "getInfoWindow: made AdultCB = " + animalMarker.getAnimal().isAdult());
miwNeuteredCB.setChecked(animalMarker.getAnimal().isNeutered());
switch (animalMarker.getAnimal().getSpecies()) {
case "dog":
miwImage.setImageResource(R.drawable.dog_icon);
break;
case "cat":
miwImage.setImageResource(R.drawable.cat_icon);
break;
default:
miwImage.setImageResource(R.drawable.cat_icon);
}
return view;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
});
R.layout.marker_info_window :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/white_border"
android:orientation="horizontal"
android:padding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/miwLocation"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:maxLines="1"
android:text="miwLocation"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:src="@drawable/dog_icon"
android:id="@+id/miwImage"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_below="@+id/miwLocation"
android:layout_alignParentStart="true"
android:layout_marginStart="18dp"
android:layout_marginTop="3dp" />
<TextView
android:id="@+id/miwAnimalName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/miwLocation"
android:layout_marginStart="30dp"
android:layout_marginTop="7dp"
android:layout_toEndOf="@+id/miwImage"
android:layout_toRightOf="@id/miwImage"
android:ellipsize="end"
android:maxLines="2"
android:textStyle="bold"
android:text="miwAnimalName"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:id="@+id/miwAnimalAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/miwLocation"
android:layout_marginStart="20dp"
android:layout_marginTop="7dp"
android:layout_toRightOf="@id/miwAnimalName"
android:text="3 yrs"
android:textStyle="bold"
android:textColor="#000000"
android:textSize="15sp" />
<CheckBox
android:id="@+id/miwAdultCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/miwAnimalName"
android:layout_marginLeft="20dp"
android:layout_marginTop="8dp"
android:layout_toRightOf="@id/miwImage"
android:text=" Adult"
android:textSize="18dp"
android:clickable="false"/>
<CheckBox
android:id="@+id/miwNeuteredCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/miwAnimalName"
android:layout_marginLeft="20dp"
android:layout_marginTop="8dp"
android:layout_toRightOf="@id/miwAdultCB"
android:text=" Neutered"
android:textSize="18dp"
android:clickable="false"/>
</RelativeLayout>
</LinearLayout>
Images of the layout design and of the resulting InfoWindow:
Aucun commentaire:
Enregistrer un commentaire