开发者

How to retrieve an image from ImageView when Click on that image?

开发者 https://www.devze.com 2023-04-04 19:28 出处:网络
i have a ImageView in the layout, when i click on the image i want to get that image into a variable and replace with another image in this Imag开发者_开发问答eView. please help me..The onClick Listen

i have a ImageView in the layout, when i click on the image i want to get that image into a variable and replace with another image in this Imag开发者_开发问答eView. please help me..


The onClick Listener will give you a View, that's the ImageView that was clicked. Cast it to an ImageView and do whatever you want with it.


in this example i have take previous image in Drawable and replace i with new image. if you set any imageview to image which stay in drawable variable(d) then use :: setBackgroundDrawable(d); is useful

 public void onClick(View v){
   ImageView i;
        i = (ImageView) findViewById(R.id.img);
        Drawable d = i.getBackground();
        i.setBackgroundResource(R.id.secondImage);

   }
0

精彩评论

暂无评论...
验证码 换一张
取 消