I need to change the image of a toggle button every time it is clicked.
Is it efficient to do this?
public void onClickToggleButton(View v) {
if(_on) {
_on=false;
myImageView.setImageDrawable(getResources().getDrawable(R.drawable.btn_off));
} else {
_on=true;
myImageView.setImageDrawable(getResources().getDrawable(R.drawable.btn_on));
}
}
Or does it mean the Drawable
will be decoded from the PNG file every time?
In which case calling getDrawable()
only twice (in onCreate()
) and keeping my own references to the 2 Drawable
s would be better.