title: How to Inflate Extended LinearLayout from XML
body: <p>Can anyone suggest a way to improve this API8 example? While they say the views could have been defined in XML, what they have in fact done is code them in java. I see why they wanted to. They have added some members to an extended LinearLayout, and the values are determined at runtime.</p>
  
  <p>According to oh, everyone in the universe, the layout directives should move to XML. But for this app, it makes sense to keep setting the text as-is in the runtime logic. So we've got a hybrid approach. Inflate the views, then populate the dynamic text. I'm having trouble figuring out how to accomplish it. Here's the source and what I tried.</p>
  
  <p>from <a href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List4.html" rel="nofollow noreferrer">API8 Examples, List4.java</a></p>
  
  <pre><code>  private class SpeechView extends LinearLayout {
       public SpeechView(Context context, String title, String words) {
          super(context);
  
          this.setOrientation(VERTICAL);
  
          // Here we build the child views in code. They could also have
          // been specified in an XML file.
  
          mTitle = new TextView(context);
          mTitle.setText(title);
          ...
  </code></pre>
  
  <p>I figured since the LinearLayout has an android:id="@+id/LinearLayout01", I should be able to do this in the OnCreate</p>
  
  <pre><code>SpeechView sv = (SpeechView) findViewById(R.id.LinearLayout01);
  </code></pre>
  
  <p>but it never hits the minimal constructor I added:</p>
  
  <pre><code>    public class SpeechView extends LinearLayout {
         public SpeechView(Context context) {
            super(context);
            System.out.println("Instantiated SpeechView(Context context)");
         }
         ...
  </code></pre>