I’m using AspectJ with Android and I’m successfully capturing calls to View.setOnClickListener() with this aspect:
public aspect Test {
pointcut callPointcut(View view, OnClickListener listener) : call(void View.setOnClickListener(OnClickListener)) && target(view) && args(listener);
@SuppressAjWarnings // Exported advice
before(View view, OnClickListener listener) : callPointcut(view, listener)
{
Log.d("AspectJ", "Attempt to set onClick listener on view " + Integer.toHexString(view.getId()));
Log.d("AspectJ", "Aspect has executed.");
Log.d("AspectJ", listener.toString());
}
}
Unfortunately, this does not capture listeners set up with android:onClick in the layout XML. Is there any way to capture this?
You wont be able to do that that way.
If I’m understanding it correctly your listening to calls of setOnClickListener() on Views.
When you set the onclick attribute in xml, its never called. The Listener is set when the View is created – directly. setOnClickListener() is never called.
The only solution would be to check all your views by hand – which is not recommend and probably not what youre looking for.