I have an application that needs the same items [5 buttons acting as tabs] in every screen. Is it possible to create a “base XML layout” that has these 5 buttons and then have all the other XML files extend from the bas layout in some way so that I don’t have to have multiple buttons that will ultimately have the same functionality.
Is there a better approach to this problem that can be supported by API 9
Create a common layout for your base activity. and then include that layout in all the layout using the
<include>tagwhich you want to make the same.After that create one Abstract Activity and then handle all the click of the buttons and code in this activity and then extends this activity in all other activity in which you have include the base layout.
For example
common buttons xml layout
Here is a xml layout in which you can include above XML file
Here android:layout_width and android:layout_height and layout are compulsory attributes
Now here is a Base Activity which handles the click of the common controls
Now one step remaining is to extend this Base activity in all your activities.
You can extend the Base activity in an activity using the extends keyword.
For example
Note: From the child activity you must call the super method of the base class to handle the click of the common controls of your base layout.
You can thus implement multiple common layout within your single activity.
Hope this will help you.
Enjoy!!