Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change source image for image view when pressed

Tags:

android

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

like image 505
Gratzi Avatar asked Nov 16 '10 10:11

Gratzi


People also ask

How do I change the source of a picture on android?

Using setBackgroundResource() method: myImgView. setBackgroundResource(R.

How do I set a picture in a picture view?

android:text="Click on the Image" android:id="@+id/textView" android:layout_marginTop="50dp"

Which file do you alter the image displayed by the image view in?

ImageView imageView = new ImageView(this); Bitmap bImage = BitmapFactory. decodeResource(this. getResources(), R. drawable.

How do you update an image within a picture?

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.


1 Answers

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)

like image 195
PrashantAdesara Avatar answered Oct 11 '22 18:10

PrashantAdesara