I have a set of views I want to always use together. An example of this may be something like:
This example is for a horizontal number picker widget, but it's the same concept.
First create the XML layout for your custom component
Then create the java class
public class HorizontalNumberPicker extends LinearLayout {
public HorizontalNumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.horizontal_number_picker, this);
}
}
Add whatever logic you need to that java class, then you can just include the custom component in your XML layout like so:
Check out this link for more information: http://developer.android.com/guide/topics/ui/custom-components.html#compound