I am Beginner in xamarin and trying to use this library (smarteist Android-Image-Slider) on android xamarin .
Library Sources:
NuGet:
https://www.nuget.org/packages/Karamunting.Android.Smarteist.AutoImageSlider/1.3.2
GitHub:
https://github.com/smarteist/Android-Image-Slider
It is working on android xamarin but I don't know how to use it, there is only android studio sample.
This class "SliderAdapterExample" is working fine now
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Smarteist.AutoImageSlider;
using BumpTech.GlideLib;
namespace PriceChecker
{
public class SliderAdapterExample : SliderViewAdapter
{
private Context context;
private int mCount;
public SliderAdapterExample(Context context)
{
this.context = context;
}
public void setCount(int count)
{
this.mCount = count;
}
public int getCount()
{
//slider view count could be dynamic size
return mCount;
}
public override int Count => 4;
public override void OnBindViewHolder(Java.Lang.Object viewHolder, int position)
{
SliderAdapterVH _viewHolder = (SliderAdapterVH)viewHolder;
_viewHolder.textViewDescription.Text = "This is slider item " + position;
switch (position)
{
case 0:
Glide.With(_viewHolder.itemView)
.Load("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.Into(_viewHolder.imageViewBackground);
break;
case 1:
Glide.With(_viewHolder.itemView)
.Load("https://images.pexels.com/photos/747964/pexels-photo-747964.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260")
.Into(_viewHolder.imageViewBackground);
break;
case 2:
Glide.With(_viewHolder.itemView)
.Load("https://images.pexels.com/photos/929778/pexels-photo-929778.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.Into(_viewHolder.imageViewBackground);
break;
default:
Glide.With(_viewHolder.itemView)
.Load("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.Into(_viewHolder.imageViewBackground);
break;
}
}
public override Java.Lang.Object OnCreateViewHolder(ViewGroup parent)
{
View inflate = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.image_slider_layout_item, null);
return new SliderAdapterVH(inflate);
}
class SliderAdapterVH : SliderViewAdapter.ViewHolder
{
public View itemView;
public ImageView imageViewBackground;
public TextView textViewDescription;
public SliderAdapterVH(View itemView) : base(itemView)
{
imageViewBackground = itemView.FindViewById<ImageView>(Resource.Id.iv_auto_image_slider);
textViewDescription = itemView.FindViewById<TextView>(Resource.Id.tv_auto_image_slider);
this.itemView = itemView;
}
}
}
}
But now I have many errors in the Activity in the image