Change source image for image view when pressed

前端 未结 16 514
闹比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:37

    don't forget to create the field "fun"

    Try this for changing image.When imageview is pressed

    Like_btn.setOnClickListener(new OnClickListener()
            {
    
                **private boolean fun = true;**
    
    
                public void onClick(View v)
                {
                    if(fun)
                    {
                    Like_btn.setImageResource(R.drawable.unlike);
                    fun=false;
                    }
                    else
                    {
                        fun=true;       
                        Like_btn.setImageResource(R.drawable.like);
                        Toast.makeText(getApplicationContext(), "Changed", Toast.LENGTH_LONG).show();
                    }
                }
            });
    

提交回复
热议问题