开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜