Skip to content

Instantly share code, notes, and snippets.

@Krumelur
Created May 6, 2016 09:44
Show Gist options
  • Save Krumelur/295b234beb49bf771a0387711860988a to your computer and use it in GitHub Desktop.
Save Krumelur/295b234beb49bf771a0387711860988a to your computer and use it in GitHub Desktop.
public override View GetView (int position, View convertView, ViewGroup parent)
{
var inflater = LayoutInflater.From (parent.Context);
var view = convertView;
if(view == null)
{
view = inflater.Inflate (Resource.Layout.InstructorRow, parent, false);
}
var photo = view.FindViewById<ImageView> (Resource.Id.photoImageView);
var name = view.FindViewById<TextView > (Resource.Id.nameTextView);
var specialty = view.FindViewById<TextView > (Resource.Id.specialtyTextView);
using(Stream stream = parent.Context.Assets.Open (instructors [position].ImageUrl))
{
((BitmapDrawable)photo.Drawable)?.Bitmap?.Recycle();
// Kind of heavy, but it prevents OOM.
GC.Collect();
Drawable drawable = Drawable.CreateFromStream (stream, null);
photo.SetImageDrawable (drawable);
}
name.Text = instructors [position].Name;
specialty.Text = instructors [position].Specialty;
return view;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment