Thursday, June 13, 2013

How to change ImageView Source - Android?

Consider you have set the source for the ImageView in your xml as below,

<ImageView  
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:id="@+id/myImgView"
            android:src="@drawable/something"/>
To change the image source programatically,

myImgView.setImageResource(R.drawable.ball);
or,

myImgView.setImageDrawable(getResources().getDrawable(R.drawable.ball));

No comments:

Post a Comment