title: How to inflate a child view?
body: <p>I'm trying to inflate a particular section of a layout however I am getting compiler errors, and am unsure what approach to take. In particular with the line - </p>
  
  <pre><code>LinearLayout childList = (LinearLayout)findViewById(R.id.listLayout). 
  //(This can be found near the bottom of Java code.)
  </code></pre>
  
  <p>I'm also unsure if I'm taking the right approach when trying to inflate the <code>listLayout</code>.</p>
  
  <p>At this stage I'm trying to have a button on top and then dynamically inflate a list of items in an Array below it.</p>
  
  <p>Any help would be much appreciated</p>
  
  <p><strong>XML</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;Button
          android:id="@+id/labelAddCourseButton"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:onClick="addCourseButton"
          android:padding="10dp"
          android:text="@string/CourseName" /&gt;
  
      &lt;LinearLayout
      android:id="@+id/listLayout"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="horizontal" &gt;     
  
      &lt;TextView
          android:id="@+id/labelModuleCode"
          android:layout_height="wrap_content"
           android:layout_width="wrap_content"
           android:layout_marginLeft="10dp"
          android:text="@string/CourseName"
          android:textSize="10dp" /&gt;
  
       &lt;TextView
          android:id="@+id/labelCourseType"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/CourseType"
          android:layout_marginLeft="10dp"
          android:textSize="10dp" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Java</strong></p>
  
  <pre><code>package com.example.mycoursetimetable;
  
  import android.os.Bundle;
  import android.app.ListActivity;
  import android.content.Context;
  import android.content.Intent;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.LinearLayout;
  import android.widget.ListView;
  import android.widget.TextView;
  
  public class MyCourses extends ListActivity {
  
      static final String TEST = "com.example.mycoursetimetable.TEST";
      String [] MODULE;
  
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_my_courses);
          MODULE = getResources().getStringArray(R.array.module);
          setListAdapter(new ListArrayAdapter(this,MODULE));
      }
  
      public void addCourseButton (View addCourseButton) 
      {
          Intent intent = new Intent(this,AddCourse.class);
          startActivity(intent);
      }
  
      public void onListItemClick(ListView l, View v, int position, long id)
      {
          super.onListItemClick(l, v, position, id);
  
          try {
          Class test = Class.forName("com.example.MyCourseTimeTable.AddCourse");
          Intent intent = new Intent(MyCourses.this, test);
  
          TextView textView = (TextView) v.findViewById(R.id.labelModuleCode);
          String module = textView.getText().toString();
  
          intent.putExtra(TEST,module);
          startActivity(intent);
          }   
          catch (ClassNotFoundException e)
          {
          e.printStackTrace();
          }             
      }    
  }
  
  class ListArrayAdapter extends ArrayAdapter&lt;String&gt; 
  {
      //Context allows the retrieval of resources such as layout
      private final Context context;
      private final String[] test;
  
      //create the ArrayAdpater
      public ListArrayAdapter(Context context, String[] test) 
      {
          super(context, R.layout.activity_my_courses, test);
          this.context = context;
          this.test = test;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) 
      {
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          //inflater  dynamically loads the layout
  
          LinearLayout childList = (LinearLayout)findViewById(R.id.listLayout);
          View rowView = inflater.inflate(R.layout.childList, parent, false);
  
          //get the textView
          TextView textView = (TextView) rowView.findViewById(R.id.labelModuleCode);
          //set the text to the string values based on position
          textView.setText(test[position]);
  
          // Change item based on its position in the string array
          String modulePosition = test[position];             
  
          //return the layout
          return rowView;
      }
  }
  </code></pre>