Reputation: 693
I am using this GoogleMap.InfoWindowAdapter
to show image
on ImageView
in the InfoWindow
but I want to handle sliding events
on it to show other images
.
Here is my code:
public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter
{
public MarkerInfoWindowAdapter(Bitmap pbitMap){}
@Override
public View getInfoWindow(Marker marker)
{
ArrayList<String> lPhotos = new ArrayList();
File file=new File("/sdcard/trip/");
File[] list = file.listFiles();
int count = 0;
String lname = "";
for (File f: list){
lname = f.getName();
if (lname.endsWith(".jpg")){
count++;
lPhotos.add(lname);
}
System.out.println("170 " + count);
}
Bitmap mBitmap = getImageFileFromSDCard(lname);
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
ImageView markerIcon = (ImageView) v.findViewById(R.id.marker_icon);
markerIcon.setImageBitmap(mBitmap);
return v;
}
@Override
public View getInfoContents(Marker marker)
{
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
ImageView markerIcon = (ImageView) v.findViewById(R.id.marker_icon);
return v;
}
}
Upvotes: 1
Views: 990
Reputation: 6078
According to here, you should setImageBitmap
in getInfoContents
instead of getInfoWindow
.
Sample code:
class MyInfoWindowAdapter implements InfoWindowAdapter{
private final View myContentsView;
boolean not_first_time_showing_info_window;
MyInfoWindowAdapter(){
myContentsView = getLayoutInflater().inflate(R.layout.custom_info_contents, null);
}
@Override
public View getInfoContents(Marker marker) {
ImageView imageView = (ImageView)myContentsView.findViewById(R.id.imgView);
TextView tvTitle = ((TextView)myContentsView.findViewById(R.id.title));
tvTitle.setText(marker.getTitle());
TextView tvSnippet = ((TextView)myContentsView.findViewById(R.id.snippet));
tvSnippet.setText(marker.getSnippet());
return myContentsView;
}
custom_info_contents.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher"
android:id="@+id/imgView"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"/>
</LinearLayout>
</LinearLayout>
For more details, please refer to here and my project on github here.
EDIT
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
}
});
Upvotes: 1