In xml layouts, one can set a onclick listener to any item using this syntax:
android:onClick="clicked"
implementing the function in the activity:
public void clicked(View v) {
...
}
This is great as it reduces code executed at run time. I've thus been on a quest to find the equivalent for OnLongClick Listeners
. I've experimenting in XML and there is no android:onLongClick...
Is there a way to set the onLongClick Listener
at compile time?
If not what are some strategies? Have an initial loading screen where the listeners get set?
The only event handler that has an XML attribute is android:onClick
. All other event handlers are registered at runtime from Java code. Technically, even android:onClick
is registered at runtime from Java code, but you do not have to write the Java code in question.