Create custom component based on LinearLayout, declaring layout in XML
Posted
by pheelicks
on Stack Overflow
See other posts from Stack Overflow
or by pheelicks
Published on 2010-05-13T16:08:49Z
Indexed on
2010/05/13
16:14 UTC
Read the original article
Hit count: 276
I've been trying to create a Compound Control in Android 1.5 (as described here) but havn't been able to find any good examples on how to do this using an XML file to specify a layout. I'm fine with creating an Activity and then loading an xml file using the following in the constructor:
setContentView(R.layout.main);
However, I want to do this in subclass of LinearLayout - so I can use this compound component in other XML layouts. Something along the lines of:
public class CustomView extends LinearLayout
{
public CustomView(Context context) {
super(context);
setupView();
}
public CustomView(Context context, AttributeSet attrs)
{
super(context, attrs);
setupView();
}
public void setupView()
{
setContentView(R.layout.custom); // Not possible
}
}
What is the correct way of going about doing this?
© Stack Overflow or respective owner