Hi Kfealz,

Take a look at the Bitmap class and BitmapFactory. I needed to set the
image from Java for an ImageButton, and ended up getting a Bitmap object
of the image(there's a call to the BitmapFactory that takes a URL) then
you can set the bitmap on the ImageView.

Ahmad 

-----Original Message-----
From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of kfealz
Sent: Friday, May 02, 2008 9:07 AM
To: Android Beginners
Subject: [android-beginners] Re: How to declare images for ImageView


I think I need to do something like this:

 private ImageView img;
img = new ImageView(context);
 img.setImageDrawable(getResources().getDrawable(R.drawable.ruski));

but I'm not sure what to send in as context.  Any thoughts?

On May 2, 8:59 am, kfealz <[EMAIL PROTECTED]> wrote:
> I have an ImageView declared like so:
>
>                 <ImageView
>                 android:id="@+id/contactImg"
>                 android:layout_width="wrap_content"
>                 android:layout_height="wrap_content"
>                 android:src="@+drawable/ruski"
>                 />
>
> Right now it uses the image "Ruski" under res/drawable.  I'd like to
> be able to change that image from Java, but I've had a lot of problems
> with it.
>
> This is what I have right now:
> if(msgFrom.equals("Ruski"))
>
((ImageView)findViewById(R.id.contactImg)).setImageDrawable(getResources
().getDrawable(R.drawable.ruski));
>         else if(msgFrom.equals("Fealz"))
>
((ImageView)findViewById(R.id.contactImg)).setImageDrawable(getResources
().getDrawable(R.drawable.fealz));
>
> but I get a null pointer exception when I run it.
>
> Any ideas appreciated!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to