Question

just wanted to make a clickable image and I don't know which option will be more efficient. What's better: a button that has a background image or a imageview that is clickable?

Was it helpful?

Solution

Adding clickListener to ImageView is a cleaner way. In the button, you may face issues like, image not being bordered properly. It can be done with changes in xml, but its an overhead.

ImageView imageView = (ImageView) findViewById(R.id.<ImageViewId>);
imageView.setOnClickListener(this);

In the onClick(View view) method, handle the click event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top