0

I have problem to launch phone's dialer when I click on digits inside my custom info window. This infowindow is appeared each time I click on a marker on a map api v2. I would like to show a tel number in the infowindow of marker, and click it to dial screen (launch dialer with my digits inserted).

This is my activity:

public View getInfoContents(Marker marker) {
    View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);

    //start phone call
    final TextView tvDialer =(TextView) v.findViewById(R.id.dialer);
    tvDialer.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
         String phoneNo= tvDialer.getText().toString();
         Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" +phoneNo));
                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(callIntent);
        }

    });
    //end phone call

    // Returning the view containing InfoWindow contents
    return v;

}

Here is my XML:

<TextView
    android:id="@+id/dialer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:autoLink="phone"
    android:text="1234567" />

Could you please help me?

jh314
  • 27,144
  • 16
  • 62
  • 82
Thanos Infosec
  • 57
  • 1
  • 10

1 Answers1

0

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 (for example, 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.

from the Google Maps V2 documentation: https://developers.google.com/maps/documentation/android/infowindows

I'd recommend enabling the dialer call on tapping the marker or if you have more than one piece of information, show some floating view(a small window) on tapping the marker, show relevant information on this view and then set the dialer call.

But if you still want to pursue your requirement, there is a workaround. Check out the following link: Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)

You can use an OnInfoWindowClickListener to listen to click events on an info window. To set this listener on the map, call GoogleMap.setOnInfoWindowClickListener(OnInfoWindowClickListener).

Community
  • 1
  • 1
Jayesh Elamgodil
  • 1,467
  • 11
  • 15
  • The whole custom infowindow just contains text. I just wish to open dialer when you click anywhere in the infowindow. No other action. – Thanos Infosec Jun 03 '15 at 15:43