Created
August 12, 2015 05:37
-
-
Save vkoppaka/ad8a22f67f8268dab202 to your computer and use it in GitHub Desktop.
Movies Adapter CardView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Android.App; | |
using Android.Views; | |
using Android.Widget; | |
namespace CardViewSample | |
{ | |
public class MovieAdapter : BaseAdapter<Movie> | |
{ | |
private readonly Activity context; | |
private readonly List<Movie> movies; | |
public MovieAdapter(Activity context, List<Movie> movies) | |
{ | |
this.context = context; | |
this.movies = movies; | |
} | |
public override Movie this[int position] | |
{ | |
get | |
{ | |
return movies[position]; | |
} | |
} | |
public override int Count | |
{ | |
get | |
{ | |
return movies.Count; | |
} | |
} | |
public override long GetItemId(int position) | |
{ | |
return position; | |
} | |
public override View GetView(int position, View convertView, ViewGroup parent) | |
{ | |
var view = convertView; | |
if (view == null) | |
{ | |
view = context.LayoutInflater.Inflate(Resource.Layout.MovieRow, parent, false); | |
} | |
var titleTextView = view.FindViewById<TextView>(Resource.Id.cardViewText); | |
var imageView = view.FindViewById<ImageView>(Resource.Id.imageView); | |
titleTextView.Text = movies[position].Title; | |
imageView.SetImageResource(Resource.Drawable.starwarslogo); | |
return view; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment