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);
}
加载中,请稍侯......
精彩评论