androidtouch

Android - ImageView On Click


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");
    }
});

Solution

  • 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"