Download and Display Image in Android

When you want to download a Image from the Web and Display it in Android in a ImageView i encountered two different approaches:

1. Download the Image and Display it:

Drawable DownloadDrawable(String url, String src_name) throws java.io.IOException {
	return Drawable.createFromStream(((java.io.InputStream) new java.net.URL(url).getContent()), src_name);
}
 
[...]
 
try {
	Drawable drw = DownloadDrawable("http://www.google.de/intl/en_com/images/srpr/logo1w.png", "src")
	ImageView1.setImageDrawable(drw);
} catch (IOException e) {
	// Something went wrong here
}

Continue reading


Find File Snippet – Depth First And Breadth First Search

Two usefull snippets, if you need to do a quick file search, here a recursive and a breadth first implementation (ignored the not-authorized-exception):
(took me only 2 mins, love .Net 🙂

Depth First Implementation:

static string[] FindFile_DepthFirst(string directoryName, string fileName)
{
   return Directory.GetFiles(directoryName, fileName, SearchOption.AllDirectories);
}

Breadth First Implementation:
Continue reading


Update GUI Control From Non-GUI-Thread Without Marshalling

In .Net when you want to update a GUI Control, for example a ListView, you have to execute your update code in the GUI Thread which controls your Form and its child GUI Objects. While you are in another Thread, you call the Invoke or BeginInvoke (for async.) method of your GUI Control for this purpose. You pass this method a delegate of your method, which contains your update code, and the GUI Thread invokes the method that is passed. Well the whole story is infact much more complicated and this article gives you a nice in-depth view on this topic:
WinForms UI Thread Invokes: An In-Depth Review of Invoke/BeginInvoke/InvokeRequred

 

This is how Microsoft wants us to manage our GUI stuff, Continue reading