I have an imageview that should be changed on click
public class Settings extends Activity implements OnClickListener
{
     private ImageView im1;
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.settings);
         im1 = (ImageView) findViewById( R.id.imageView1 );
         im1.setOnClickListener(this);
     }
     @Override
     public void onClick(View v)
     {
         // TODO Auto-generated method stub
         if (v == im1 )
         {
             Log.d("test", "hey!");
             v.setBackgroundResource(R.drawable.img1);
         }
     }
}
when clicked the method runs and prints out "hey!" but the image won't change?
EDIT: forgot to mention that imageview contains another image provided by xml layout file
By convention, you should be using setImageResource(R.drawable.img1); (or setImageDrawable(getResources().getDrawable(R.drawable.img1));) instead of setBackgroundResource(R.drawable.img1);.
  ImageView i = (ImageView) findViewById( R.id.imageView1 );
  i.setImageResource(R.id.logo);
   or
  i.setBackgroundResource(R.drawable.icon);
                        UPDATE
Now, you can use like below,
imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.img1));
                        Try This In API 25
imgSchedule.setImageDrawable(getResources().getDrawable(R.drawable.circle_image_selected));
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With