Change source image for image view when pressed

前端 未结 16 571
闹比i
闹比i 2020-12-08 19:53

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 anothe

16条回答
  •  爱一瞬间的悲伤
    2020-12-08 20:47

    ImageButton Demo_button = (ImageButton)findViewById(R.id.firstimage);
    ImageButton second_button = (ImageButton)findViewById(R.id.secondimage);
    
    // when you click this demo button
    Demo_button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
        Demo_button.setImageResource(R.drawable.secondimage);
        second_button.setImageResource(R.drawable.firstimage);
       }
    }
    
    second_button.setOnClickListener(new OnClickListener() {
       public void onClick(View v) {
          Demo_button.setImageResource(R.drawable.firstimage);
          second_button.setImageResource(R.drawable.secondimage);
       }
    }
    

    I Hope u want to like that Right???

提交回复
热议问题