Advertisement
banyucenter

CustomListAdapter.cs

Nov 8th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2. using Android.Widget;
  3. using Android.App;
  4. using System.Collections.Generic;
  5. using Android.Views;
  6. using Android.Media;
  7. using System.Net;
  8. using System.Threading.Tasks;
  9. using System.IO;
  10. using Android.Graphics;
  11.  
  12. //Adapter untuk load list view kabupaten
  13. namespace PariwisataApp
  14. {
  15.     public class CustomListAdapter : BaseAdapter<Kabupaten>
  16.     {
  17.         public CustomListAdapter()
  18.         {
  19.         }
  20.         Activity context;
  21.         List<Kabupaten> list;
  22.  
  23.         public CustomListAdapter(Activity _context, List<Kabupaten> _list) : base()
  24.         {
  25.             this.context = _context;
  26.             this.list = _list;
  27.         }
  28.  
  29.         public override int Count
  30.         {
  31.             get { return list.Count; }
  32.         }
  33.  
  34.         public override long GetItemId(int position)
  35.         {
  36.             return position;
  37.         }
  38.  
  39.         public override Kabupaten this[int index]
  40.         {
  41.             get { return list[index]; }
  42.         }
  43.  
  44.         public override View GetView(int position, View convertView, ViewGroup parent)
  45.         {
  46.             View view = convertView;
  47.  
  48.             // re-use an existing view, if one is available
  49.             // otherwise create a new one
  50.             if (view == null)
  51.                 view = context.LayoutInflater.Inflate(Resource.Layout.ListRow, parent, false);
  52.  
  53.  
  54.             Kabupaten item = this[position];
  55.             view.FindViewById<TextView>(Resource.Id.NamaKabupaten).Text = item.nama_kabupaten;
  56.  
  57.             using (var imageView = view.FindViewById<ImageView>(Resource.Id.Foto))
  58.             {
  59.                 string url = Android.Text.Html.FromHtml(item.foto).ToString();
  60.  
  61.                 //Download and display image
  62.                 Koush.UrlImageViewHelper.SetUrlDrawable(imageView,
  63.                                                         url, Resource.Drawable.loadimage);
  64.             }
  65.             return view;
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement