Alright so how when i click a button? it will change the a image to a different image
my xml of the image i want to change when button press:
<ImageView
    android:id="@+id/bluebtn1" 
    android:src="@drawable/buttonblue" 
    android:layout_width="60dp" 
    android:layout_height="60dp"  
    android:layout_marginLeft="33dp"
    android:layout_marginTop="140dp"></ImageView>
and here is my java code ill be doing when you press the button
    case R.id.redbtn1:
            if (lvl1.getText().equals("1")) {
                lvl1.setText("2");
// Here is where the code goes to change the image
            } else {
                Toast.makeText(main.this, "YOU LOSE!", Toast.LENGTH_SHORT).show();
            }
        break;
                Put this in your click listener.
ImageView blueBtn  = (ImageView)findViewById(R.id.bluebtn1);
blueBtn.setImageResource(R.drawable.YOUR_NEWIMAGE);
This should work.
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