Created
February 21, 2014 21:10
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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