Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've finally made it work.</p> <p>First of all I've extended Annotation to add additional fields:</p> <pre><code>public class CustomAnnotation extends Annotation { private CustomObject cObject; public CustomObject getCustomObject() { return cObject; } public void setCustomObject(CustomObject cObject) { this.cObject = cObject; } public CustomAnnotation(GeoPoint point, String title, String snippet,CustomObject cObject) { super(point, title, snippet); this.cObject = cObject; } </code></pre> <p>I created a layout for the CallOutView:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/content" android:paddingLeft="5dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;LinearLayout android:id="@+id/balloon_inner_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_vertical"&gt; &lt;ImageView android:id="@+id/image" android:layout_width="50dip" android:layout_height="50dip" android:contentDescription="@string/descr_image" android:src="@drawable/stub" android:scaleType="centerCrop" android:layout_gravity="center_vertical"/&gt; &lt;LinearLayout android:paddingLeft="5dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;TextView android:id="@+id/price" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/address" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/sup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone"/&gt; &lt;TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/rooms" android:visibility="gone"/&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>In my MapActivity class I've implemented OnAnnotationSelectionChangedListener. Dont forget to set the listener.</p> <p>In MapActivity#onAnnotationSelected I cast the annotation received to my CustomAnnotation so I can use the additional Fields, Inflate a layout into a View Object and setText to all my TextViews:</p> <pre><code>@Override public void onAnnotationSelected(PolarisMapView mapView, MapCalloutView calloutView, int position, Annotation annotation) { CustomAnnotation ca = (CustomAnnotation) annotations.get(position); View view = (View)getLayoutInflater().inflate(R.layout.balloon_test, null); CustomObject object = ca.getCustomObject(); TextView txView = (TextView)view.findViewById(R.id.field1); txView.setText(object.getField1()); txView.setVisibility(View.VISIBLE); ... //set aditional data in your callout ... calloutView.setDisclosureEnabled(true); calloutView.setClickable(true); calloutView.setCustomView(view); calloutView.show(mPolarisMapView, annotation.getPoint(), false); } </code></pre> <p>That's all. Hope it helps somebody.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload