How to tell a View subclass to load its own layout
<p>I have a custom View subclass which I am calling <code>ListItem</code> which has a layout (<code>res/layout/list_item.xml</code>). I cannot get my <code>ListItem</code> class to load the layout xml file.</p>

<pre><code>public class ListItem extends View{

    private TextView title, subtitle;

    public ListItem(Context context) {
        this(context, null);
    }

    public ListItem(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ListItem(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        //I want to load/inflate the view here so I can set title and subtitle.
    }
}
</code></pre>

<p>I can get the view to load by doing this, but I don't like the fact that it happens outside of the scope of the <code>ListItem</code> class. It seems like <code>ListItem</code> should be responsible for loading its own view. From ListViewAdapter.java:</p>

<pre><code>public View getView(int position, View convertView, ViewGroup parent) {
    ListItem entry = items.get(position);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_item, null);
    }

    TextView title = (TextView) convertView.findViewById(R.id.title);
    title.setText(entry.getTitle());

    TextView subtitle = (TextView) convertView.findViewById(R.id.subtitle);
    subtitle.setText(entry.getSubtitle());

    return convertView; 
}
</code></pre>

<p>Again, I want to load the layout from within the <code>ListItem</code> class. Is it possible for a view to load its own layout?</p>
