frankelot
frankelot

Reputation: 14409

Print name of view catching click event on Android

So I have a stack of views, some of them are transparent, and Im not sure which one is preventing the click event to fire on the view it is supposed to. Is there a way of printing on the terminal the name/id of the view that is catching the click event?. (Already used the "show layout bounds" option on the developer tools, did not help me)

Thanks!

Upvotes: 1

Views: 176

Answers (1)

0xDEADC0DE
0xDEADC0DE

Reputation: 2473

You could use the tag of each view to set a distinct text and in your OnClickListener you could log the tag like

new View.OnClickListener() {

    public void onClick(View v) {
        Log.i("Clicked View", v.getTag())
    }
};

EDIT:

Note that when you have a transparent view (alpha = 0) it can still catch click events. Set a view's visibility to View.GONE to disable the OnClickListener

Upvotes: 1

Related Questions