Android - ImageView On Click
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;
}
});
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"
1) First make your image view clickable by adding-> android:clickable="true" .
2) Then go to your java file and add declare a variable
for example-> private static ImageView imgview;
3) Then add this functionality:
public void OnclickButtonListener() {
imgview = findViewById(R.id.imageView3);
imgview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(timetable.this,MapsActivity.class);
startActivity(intent);
}
});
}
and call this function in the constructor. Hopefully this would work.