Submitted by Manmath Ray as a part of the First Android Tutorial Contest.[/align]
What you learn: The basic idea behind this tutorial is to give a common way to add footer to Android application irrespective of Activity and view designed for a particular screen. .
Problems/Questions: Write them right below...
- Defining a common footer for all screens
- Adding Footer to a List Activity
- Adding Footer to a Form
Difficulty: 2 of 5
What it will look like:
See the footer remaining on all Activities.[/align]
A footer is a typical requirement for most of the Application. There may be footer in all type of screen or there may not be footer in some screens. So design should be in such a way that irrespective of screens we can add or remove the footer.
1. Footer view needs to be defined in separate xml file so that we can generate the footer view when we need for any of the screen.
2. The screen layout which requires the Footer needs to be defined inside the linear layout so that we can add the footer to the existing layout inside the Linear Layout. This additional External Linear Layout is used to wrap the Existing view and the footer view. (Why Linear Layout? This is a tested Result, no specific reason is known to me, if any one knows can explain?)
3. There should be common method which will return the Footer view with Layout defined on it. Each of the Activity can find the Linear Layout ID as discussed in step -2 in runtime and add the defined footer view inside it, We need to define the footer view in some java classes which can be accessible for any of the Activities.
Description with Example:
As shown in the screen shots, There are two screens one is Form another is Expandable list. The code below will show you how to add the footer in both the screens.
1. Defining footer View
2. Defining sample Form and List
The marked part on both the screen design are something related to adding footer and rest of the code is similar to designing a simple scrollable form. The points to be considered are…
1. Adding the External Linear Layout whose id is ticketId in case of Form and listId in case of Expandable List. This id can be used for adding the footer to it in runtime while creating the screen.
2. We need to scroll the window without including the footer and Footer will be added in runtime so it is required to specify some space for footer while designing the form or list. android:layout_weight="1.0" is used to specify the space for footer after scrolling space or the list view.
3. The highlighted point for the view after which footer will reside must have following properties.
3. Defining a method to get the footer view
This method needs to define in such a way that it can be accessible to All the Activities. This method is used to create a footer view with certain layout parameter and returns the footer view.
4. Adding Footer to Activities
This is how footer is going to be added when an screen is created.
The Full Source:
Manmath Ray (Senior Engineer)