Android Developer Tutorials and Blog

Hi guys, read a post where someone wanted to load a url image in an ImageView and show a loading spinner whilst this was happening. So I thought it would be a fun exercise for me to do.

I originally posted this here: AndDev but have now migrated to my own blog.

Ok so i’ve implemented a View that shows a loading spinner whilst it is retrieving an image from the web.
This is useful when people have slow http connections and you at least want to show them that your loading something!

Loading

Image Loaded

To start with you will need:

<uses-permission android:name="android.permission.INTERNET" />

in your manifest.

Ok this is the ImageView Object, it is mostly self explanatory, just add it to your project package:

Yes I have Internet permission in manifest file.In logcat there is no errors. I have to load the image via code not in xml. I have set width and height in XML for that ImageView. Shoud I set layout Layout params in code too?

I found something:
When I change minSdk from 4 to 3 the Image fills the screen, BUT it looks like the whole layout gets scaled (Action Bar is a lot to big, buttons seem to jump out of the screen, Option-items are to big for the screen and only readable halfly, …)

i have used ur tutorial ,end almost everything’s look fine,but image does not display,i know that ur code is perfect but something is wrong either with my eclipse or my AVD ,i have given the user permission for internet in manifest file,and set the proxy address in my avd so browser is run on emulator ,but noe i have stuck ,any webservices does not run because this issue,
can u help?

Hi, I am trying to experiment with your code, but I am getting errors just trying to run it. one of the errors is
“button cannot be resolved or is not a field”. I find this error in the ImageExampleXML.java file. Another error in the same place is the main cannot be resolved or is not a field? what does this mean? Thank you for your time

Hmm you could pass the ImageView to the ASyncTask but be careful because you would be passing a context to your whole Activity. I would just create an interface that the ASyncTask could call when it is finished and let your Activity worry about updating the ImageView, that way ut keeps a nice degree of separation

Just want to say thanks for the code, its really helped me develop my first application. Thanks to you my first app should be in the market place soon enough.

I’ve one question, How does the Android OS know that Tutmenu.java is the first file that should be run, i can’t see anything in the code that mentions it. I’m guessing its specified somewhere else the code?