That's fine for my purposes but I think it matches less closely to what
Android does:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/ImageView.java

setImageResource(int resId) checks if the current resource id is the same
as the one passed in, and if they're the same, it does nothing, rather than
call setImageDrawable(null). Since Java initializes the field mResourceId
to 0, setImageResource() acts as if the current resource id is 0, so
passing in 0 the first time setImageDrawble() is called will also do
nothing. I'm guessing this wasn't intentional, since it looks like if you
call setImageDrawable() with a valid id and then later call it with 0 it
will blow up.

Of course my team has code that relies on being able to pass in 0.

Let me know if you still want me to change it.



On Wed, Sep 18, 2013 at 4:20 PM, Jake Wharton <notifications@github.com>wrote:

> In src/main/java/org/robolectric/shadows/ShadowImageView.java:
>
> > @@ -35,7 +35,9 @@ public void setImageDrawable(Drawable drawable) {
> >
> >    @Implementation
> >    public void setImageResource(int resId) {
> > -    setImageDrawable(buildDrawable(resId));
> > +    if (resId != 0) {
> > +      setImageDrawable(buildDrawable(resId));
>
> Yeah I think you want something like this:
>
> setImageDrawable(res != 0 ? buildDrawable(resId) ? null);
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/robolectric/robolectric/pull/691/files#r6449938>
> .
>