I have a scroll view with lots of image buttons. I want to change the image for an image button when it's pressed. The thing is that I want the image to remain until another image button is pressed. That's why I couldn't use a selector. What is the best practice to achieve his?
Best Regards
Using setBackgroundResource() method: myImgView. setBackgroundResource(R.
android:text="Click on the Image" android:id="@+id/textView" android:layout_marginTop="50dp"
ImageView imageView = new ImageView(this); Bitmap bImage = BitmapFactory. decodeResource(this. getResources(), R. drawable.
In this blog you will learn how to make Button click ImageView change the Image in Android is Below. First of all create New Project and give the Name And MainACtivity name all that. Now open the MainActivity. // Inflate the menu; this adds items to the action bar if it is present.
You want to do this.
ImageButton Demo_button = (ImageButton)findViewById(R.id.firstimage); // when you click this demo button Demo_button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Demo_button.setImageResource(R.drawable.secondimage); } }
Try this. (updated setset to set)
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