Async ImageView in MonoDroid
Can anybody give me an example how I would download an image asynchroniously and display it in an ImageView in MonoDroid.
Im tyring to port an开发者_C百科 project from MonoTouch to MonoDroid, but I'm having quite some problems with this part...
Maybe this is what you are looking for:
public class Activity1 : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.SetContentView(Resource.Layout.layout1);
WebClient web = new WebClient();
web.DownloadDataCompleted += new DownloadDataCompletedEventHandler(web_DownloadDataCompleted);
web.DownloadDataAsync(new Uri(@"http://your.image.com"));
}
void web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
Bitmap bm = BitmapFactory.DecodeByteArray(e.Result, 0, e.Result.Length);
FindViewById<ImageView>(Resource.Layout.layout1).SetImageBitmap(bm);
}
}
I haven't tested this one, but I think it should do the job :)
/Nicklas
精彩评论