The problem is that I cannot click on the URL "www.news.com" displayed on andoid map v2 inside custom infowindow of a marker. In xml layout file I have:
<TextView
android:id="@+id/web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:background="#ADD8E6"
android:text="www.google.gr"
android:linksClickable="true"/>
In Java activity file I have:
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker marker) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
TextView tvTitle = (TextView) v.findViewById(R.id.title);
tvTitle.setText(marker.getTitle());
TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
tvSnippet.setText(marker.getSnippet());
// URL
final TextView tvURL =(TextView) v.findViewById(R.id.web);
tvURL.setText("www.news.com");
Linkify.addLinks(tvURL, Linkify.WEB_URLS);
// URL
The link is showing properly with blue color and underline, but I found the its just a dead link. Nothing is happening if we try to click it. What I have to do to make the link active?
New code inserted inside java file:
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker marker) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
TextView tvTitle = (TextView) v.findViewById(R.id.title);
tvTitle.setText(marker.getTitle());
TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
tvSnippet.setText(marker.getSnippet());
// URL
final TextView tvWeb =(TextView) v.findViewById(R.id.web);
tvWeb.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.news.com"));
startActivity(viewIntent);
}
});
XML used the same:
<TextView
android:id="@+id/web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:background="#ADD8E6"
android:text="www.news.com"
android:linksClickable="true"/>
Still problem exists..URL link is not active, I cannot open browser.
Now URL link is opening to mobile browser when I click on custom infowindow.
mMap.addMarker(new MarkerOptions().position(new LatLng(39.686286, 19.838443)).title("Hi").snippet("Name, Surname, phone: 1093595, website: www.news.com").icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.news.com"));
startActivity(viewIntent);
}
});
But I have around 300 markers and for each marker I wish to open a separate URL link. How can I implement this?
UPDATE CODE:
mMap.addMarker(new MarkerOptions().position(new LatLng(36.84449, 22.99999)).title("KALOGRIA").snippet("Name: Messinia \nSurname: Stoupa \nphone: +99999999 \nwebsite: http://www.news.com/").icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener()
{
@Override
public void onInfoWindowClick(Marker marker)
{
//String webUrl = marker.getSnippet();
String snippetStr = marker.getSnippet();
String webUrl = snippetStr.substring(snippetStr.lastIndexOf("website:") + 1);
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webUrl));
startActivity(viewIntent);
}
});