0

In Xamarin, how can I get the autolink to work with some TextViews that are displayed inside a Google Map InfoWindow.

Here is my custom_info_window XML code:

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

    <TextView
        android:id="@+id/Phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:autoLink="phone"/>

    <TextView
        android:id="@+id/Web"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:autoLink="web"/>

</LinearLayout>

Here is my InfoWindow class:

public class InfoWindow : Java.Lang.Object, GoogleMap.IInfoWindowAdapter
{
    public View GetInfoContents(Marker p0)
    {
        var inflater = Application.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;

        View v = inflater.Inflate(Resource.Layout.custom_info_window, null);

        TextView title = (TextView) v.FindViewById(Resource.Id.Phone);
        title.Text = "Phone number: 0800 32 32 32";

        TextView description = (TextView) v.FindViewById(Resource.Id.Web);
        description.Text = "Email address: me@me.com";

        return v;
    }

    public View GetInfoWindow(Marker p0)
    {
        return null;
    }
}

When I click on a Marker, I show the InfoWindow, and it is correctly formatted as coded in the InfoWindow class.

However, when I click on either of the autolink items, the autolink does not work. A click on the InfoWindow only registers as a whole InfoWindow click, and does not separate into the two distinct TextViews.

Can I please have some help with this?

Thanks in advance

Garry
  • 1,251
  • 9
  • 25
  • 45

3 Answers3

0

You can't without using some dirty hack.

The InfoWindow is not a live view, it's just an image generated from the view you supplied. So any event won't be fired.

But, if you really really need to do it, this is the best way : Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps) I used it myself and it is great (and I'm using Xamarin).

Example :

This is the MapWrapper : http://pastebin.com/CDfxVZvi

This is the Adapter : http://pastebin.com/rHsjxxyn

This is the Touch listener : http://pastebin.com/4kMTygfE

Then I create everything I need : http://pastebin.com/AGyRTnu4

It is a bit more complicated than in Java because we have to pass every objects in the constructors. Don't forget to put a MapWrapper around the map container in your layout.

Community
  • 1
  • 1
Stephane Mathis
  • 6,542
  • 6
  • 43
  • 69
  • Stephane, I see that the link is not using Xamarin. Are you able to help me with the code to get it working in Xamarin? It would save me a lot of time. Maybe just some simple code examples. – Garry Feb 20 '14 at 09:03
  • I've added the code. Took me about a day, so have fun doing some other stuff ;) – Stephane Mathis Feb 20 '14 at 09:53
  • Stephane, I am having a bit of trouble tying all the code together. Do you have a simple Xamarin project with just the relevant code that I can have a look at? I would be greatly appreciative :) – Garry Mar 06 '14 at 06:41
0

You can't get any help with what you want to achieve, for one simple reason. what you see in the InfoWindow is not the layout you defined but an image that was drawn from it. meaning what you trying to do with the InfoWindow is not possible.

From Google's documentation:

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
0

Try this in xml

android:linksClickable="true"

StefanoM5
  • 1,327
  • 1
  • 24
  • 34