Skip to content

Instantly share code, notes, and snippets.

@grantamos
Created February 21, 2014 21:10
Show Gist options
  • Save grantamos/9143603 to your computer and use it in GitHub Desktop.
Save grantamos/9143603 to your computer and use it in GitHub Desktop.
Allows for an ImageView to be reset back to the original src attribute.
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* Created by granta on 2/21/14.
*/
public class DefaultImageView extends ImageView {
private int mCachedResourceId = 0;
public DefaultImageView(Context context, AttributeSet attrs) {
super(context, attrs);
mCachedResourceId = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", mCachedResourceId);
}
public DefaultImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mCachedResourceId = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", mCachedResourceId);
}
public int getDefaultResourceId() {
return mCachedResourceId;
}
public void resetToDefault() {
setImageResource(mCachedResourceId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment