MainActivity.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using Android.App;
  3. using Android.Content;
  4. using Android.Runtime;
  5. using Android.Views;
  6. using Android.Widget;
  7. using Android.OS;
  8. using System.Collections.Generic;
  9. namespace UrlImageViewHelperSample
  10. {
  11. [Activity (Label = "UrlImageViewHelper", MainLauncher = true)]
  12. public class MainActivity : ListActivity
  13. {
  14. PlaceCageAdapter adapter;
  15. protected override void OnCreate (Bundle bundle)
  16. {
  17. base.OnCreate (bundle);
  18. adapter = new PlaceCageAdapter (this);
  19. ListView.Adapter = adapter;
  20. }
  21. }
  22. public class PlaceCageAdapter : BaseAdapter<string>
  23. {
  24. public PlaceCageAdapter (Activity context)
  25. {
  26. Context = context;
  27. }
  28. public Activity Context { get;set; }
  29. public override long GetItemId (int position) { return position; }
  30. public override string this [int index] { get { return Cats.Urls [index]; } }
  31. public override int Count { get { return Cats.Urls.Length; } }
  32. public override View GetView (int position, View convertView, ViewGroup parent)
  33. {
  34. var view = convertView
  35. ?? Context.LayoutInflater.Inflate (Resource.Layout.ListItem, parent, false);
  36. var img = view.FindViewById<ImageView> (Resource.Id.imageView);
  37. var txt = view.FindViewById<TextView> (Resource.Id.textView);
  38. var url = Cats.Urls [position];
  39. txt.Text = url;
  40. Koush.UrlImageViewHelper.SetUrlDrawable (img, url);
  41. return view;
  42. }
  43. }
  44. }