You cannot avoid the realization of this listener in all your actions in any case. But you can do it in a slightly more organized way:
You can write your own header layout for your application ( /res/layout/header.xml ), in which you have an βLoginβ button with a set for listening to clicks (pointing to the onSignInClicked method):
android:onClick="onSignInClicked"
Then you include this header in each action layout:
<include android:id="@+id/header" layout="@layout/header" />
You can also create an interface that contains the declaration of the onSignInClicked method, and with all your actions that implement this interface, you force them to define the body of the onSignInClicked method.
What you are actually doing there can also be
- static method inside a global accessible class, or
- A well parameterized method inside your
Application extension class.
therefore, in all your actions this method can be:
public static void onSignInClicked(View view) {
or
public static void onSignInClicked(View view) {
If you choose the second method, be sure to update your androidManifes.xml by setting the name attribute of your Application tag:
<application android:name=".MyApplication" [...]
source share