Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't avoid implementing that listener in all of your activities in either ways. But you can do it in a bit more organized way:</p> <p>You could write a custom header layout for your application (<code>/res/layout/header.xml</code>), in which you have the "Sign In" button with a click listener set (pointing to an <code>onSignInClicked</code> method):</p> <pre><code>android:onClick="onSignInClicked" </code></pre> <p>Then you include this header to each activity layout:</p> <pre><code>&lt;include android:id="@+id/header" layout="@layout/header" /&gt; </code></pre> <p>You could also create an interface which contains an <code>onSignInClicked</code> method declaration, and by all your activities implementing that interface you force them to define the <code>onSignInClicked</code> method's body.</p> <p>What you actually do there can also be wrapped into </p> <ul> <li>a static method inside a globally accessible class, or</li> <li>a well-parametrized method inside your <code>Application</code> extension class.</li> </ul> <p>so in all of your activities this method can be:</p> <pre><code>public static void onSignInClicked(View view) { // static method with call with reference to the current activity SignInHelper.doSignIn(this); } </code></pre> <p>or </p> <pre><code>public static void onSignInClicked(View view) { // global method in your `Application` extension // with reference to the current activity ((MyApplication)getApplicationContext()).doSignIn(this); } </code></pre> <p>If you choose the second way, don't forget to update your <code>androidManifes.xml</code> by setting the <code>name</code> attribute of your <code>application</code> tag:</p> <pre><code>&lt;application android:name=".MyApplication" [...] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload