Skip to content

Instantly share code, notes, and snippets.

@jamesmontemagno
Created November 19, 2013 20:51
Show Gist options
  • Save jamesmontemagno/7552333 to your computer and use it in GitHub Desktop.
Save jamesmontemagno/7552333 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using Android.App;
using Android.Views;
using Android.Widget;
using DNR.Droid;
using DNR.Portable;
namespace DRN.Droid
{
public class PodcastsAdapterHelper : Java.Lang.Object
{
public TextView Title { get; set; }
}
public class PodcastsAdapter : BaseAdapter
{
List<PodcastEpisode> podcasts = new List<PodcastEpisode>();
readonly Activity activity;
public override View GetView(int position, View convertView, ViewGroup parent)
{
PodcastsAdapterHelper helper;
if(convertView == null)
{
var view = activity.LayoutInflater.Inflate(Resource.Layout.PodcastItem, parent, false);
helper = new PodcastsAdapterHelper();
helper.Title = view.FindViewById<TextView>(Resource.Id.textView1);
view.Tag = helper;
}
else
{
helper = (PodcastsAdapterHelper)convertView.Tag;
}
var view = convertView ?? activity.LayoutInflater.Inflate(Resource.Layout.PodcastItem, parent, false);
//var nameView = view.FindViewById<TextView>(Resource.Id.textView1);
var descriptionView = view.FindViewById<TextView>(Resource.Id.textView2);
var image = view.FindViewById<ImageView>(Resource.Id.podcastImage);
image.SetImageResource(Resource.Drawable.dnr_logo);
nameView.Text = podcasts[position].Name;
descriptionView.Text = podcasts[position].Description;
return view;
}
/// <summary>
/// Gets or sets the podcasts
/// </summary>
public List<PodcastEpisode> Podcasts
{
get { return podcasts; }
set { podcasts = value; }
}
public PodcastsAdapter(Activity activity)
{
this.activity = activity;
}
public override Java.Lang.Object GetItem(int position)
{
return null;
}
public override long GetItemId(int position)
{
return -1;
}
public override int Count
{
get
{
return podcasts.Count;
}
}
}
}
@jamesmontemagno
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment