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
-~----------~----~----~----~------~----~------~--~---