Im trying to trace a click when my image view is clicked, but I cannot seem to pick up the touch, any ideas?
imgView.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Log.v(TAG, " click");
}
});
Using clickable imagesYou can turn any View , such as an ImageView , into a button by adding the android:onClick attribute in the XML layout. The image for the ImageView must already be stored in the drawable folder of your project.
To make a View clickable so that users can tap (or click) it, add the android:onClick attribute in the XML layout and specify the click handler. For example, you can make an ImageView act like a simple Button by adding android:onClick to the ImageView . In this task you make the images in your layout clickable.
Images normally aren't clickable, therefore I would suggest that you put the definition
android:clickable="true"
android:focusable="true"
in your layout.xml to the imageView.
If this is not helping, please edit+update your question and show us the part of your layout, where you define the image to have a look at it.
EDIT: Tried it, and your code worked with me too - even with the upper case id name. Can you please have a close look at your LogCat? Mine sometimes doesn't really update, as long as I don't choose the device again.
To do so in Eclipse, go to the View "Devices" (or show it first via "Window") and click once on your device / virtual device.
If you still don't find your log entry in the LogCat-View, try to create a filter (via the green plus and giving it the String you defined with TAG
as "by Log Tag").
Have a look at android developers > Using DDMS at the section "Using LogCat"
You forgot to override the onClick method. This works for me and should do for you as well :-)
imgView.setOnClickListener(new View.OnClickListener() {
//@Override
public void onClick(View v) {
Log.v(TAG, " click");
}
});
Here's to get the X and Y coordinates:
imgView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// X = event.getX()
// Y = event.getY()
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With