So I'm trying to implement an horizontal scroll in an InfoWindow. I'm using google maps, and I want to implement an horizontal scroll with images in my custom InfoWindowAdapter.
So, I fill up an arraylist of integers with the resource ID of an example image.
As soon as I set the adapter of the recyclerview, only 1 item is shown, even though the debug stops 10 times when it gets the length of the item count on the recycler view adapter.
So, My RecyclerView Adapter is the following:
public class ImagesPreviewAdapter extends RecyclerView.Adapter<ImagesPreviewAdapter.ImagesHolder> {
public ArrayList<Integer> list;
public class ImagesHolder extends RecyclerView.ViewHolder {
ImageButton imgImage;
public ImagesHolder(View itemView) {
super(itemView);
imgImage = (ImageButton) itemView.findViewById(R.id.img_preview);
}
}
public ImagesPreviewAdapter(ArrayList<Integer> list) {
this.list = list;
}
@Override
public ImagesHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_row_stop_image, parent, false);
return new ImagesHolder(view);
}
@Override
public void onBindViewHolder(ImagesHolder holder, int position) {
int imageid = list.get(position);
holder.imgImage.setImageResource(imageid);
}
@Override
public int getItemCount() {
return list.size();
}
}
And I set the adapter of the RecyclerView as following:
public View getInfoContents(Marker marker) {
ArrayList<Integer> images = new ArrayList<>();
ImagesPreviewAdapter adapter;
for(int i = 0; i < 10; i++) {
images.add(R.drawable.torres2);
}
adapter = new ImagesPreviewAdapter(images);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
recyclerImages.setLayoutManager(mLayoutManager);
recyclerImages.setItemAnimator(new DefaultItemAnimator());
recyclerImages.setAdapter(adapter);
}
And my InfoWindow xml for the layout of the infowindow is the following:
<android.support.v7.widget.RecyclerView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/recycler_images"
android:layout_below="@+id/img_rua"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:orientation="horizontal">
</android.support.v7.widget.RecyclerView>
It ends up only showing one image, when I have clearly made a list with 10 images ....
This is the final result (the black boxes is an example of what I want to achieve