murphy wrote:
> Hi all, I'm trying to get an image to display from an internet source
> but nothing it coming up on my screen. After the button click which
> calls the code I am presented with a blank screen. The code I'm using
> is:
> 
> try {
>                       URL url = new URL("http://code.google.com/android/
> images/logo_android.gif");
>                       URLConnection conn = url.openConnection();
>                       conn.connect();
>                       InputStream is = conn.getInputStream();
>                       BufferedInputStream bis = new BufferedInputStream
> (is);
>                       Bitmap bm = BitmapFactory.decodeStream(bis);
>                       bis.close();
>                       is.close();
> 
>                       ImageView image = (ImageView)findViewById
> (R.id.timetableImage);
>                       setContentView(R.layout.timetable);
>                       image.setImageBitmap(bm);
> 
>                   } catch (Exception e) {
>                       // TODO Auto-generated catch block
>                                       e.printStackTrace();
>                       }
> 
> Can any one see what's wrong?

Yes. You're calling setContentView().

In most activities, setContentView() is called once, early in
onCreate(). It is infrequently called in an event handler (e.g., button
click callback).

More importantly, any widgets you got after the first setContentView()
and before the second setContentView() are unusable. Hence, your
findViewById() call immediately before the setContentView() will return
you a widget...but that widget is then taken off the screen by the
setContentView().

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to