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?

1

1 Answer

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:

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).

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.