I have nothing against fragments, and yes, this is the way to go, but for a novice Android developer, you can achieve what you are trying to do with <include> and basic actions.
This article perfectly explains the use of <include> s, but to summarize, you can have an XML layout file that you can "include" in another layout, rather than rewriting the same stuff over and over again.
For the functionality of the headers and footers (assuming that they do something when clicked), you can create a basic activity that you can extend instead of the usual android Activity . Define the logic for the header and footer clicks in this basic action, for example, using this code example:
public class MyBaseActivity extends Activity { ... public void onHeaderClick(View view) {
In your layout (the one that you have as a separate xml) add the onClick attribute to your header / footer by assigning the method name in the base action.
such as
android:onClick="onHeaderClick"
Then it's just a matter of expanding MyBaseActivity for all of your actions that have headers and footers.
source share