Created
July 17, 2015 05:13
-
-
Save vkoppaka/ad40e7631abf6bb33bb9 to your computer and use it in GitHub Desktop.
Movie Adapter
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 AdapterDemo2 | |
{ | |
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.titleTextView); | |
var directedByTextView = view.FindViewById<TextView>(Resource.Id.directedByTextView); | |
var releasedDateTextView = view.FindViewById<TextView>(Resource.Id.releasedDateTextView); | |
titleTextView.Text = movies[position].Title; | |
directedByTextView.Text = "Directed by: " + movies[position].Director; | |
releasedDateTextView.Text = "Released on: " + movies[position].ReleaseDate.ToShortDateString(); | |
return view; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment