title: Adding views to TableLayout inside a fragment during runtime
body: <p>I've looked through the similar questions and not yet found an answer. I will eventually be adding each of my <code>View</code>s after acquiring data from a SQL db, but for now, I am simply trying to add a set of views so I can get my layout working. I have a main activity with a fragment manager that gets my tabs flowing and loading just fine, so I don't think I need to provide that code here. </p>
  
  <p>Here is the code for the fragment:</p>
  
  <pre><code>public class EconFragment extends Fragment {
  
  private ViewGroup container;
  
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      populateQuestions(container, inflater);
      return inflater.inflate(R.layout.econfragment, container, false);
  
  }
  
  
  public void onPause() {
      super.onPause();
      container.removeAllViews();
  }
  
  private void populateQuestions(ViewGroup v, LayoutInflater inflater) {
      container = v;
      int count = 10;
      int runner = 0;
  
  
      while (runner &lt; count) {
      View question = inflater.inflate(R.layout.question, null);
      question.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
      container.addView(question, runner);
      runner++;
      }
  }
  }
  </code></pre>
  
  <p>So while this should populate in more than one Question.xml View into the container, I only have one show up. It's interesting to note that I can observe the delay as runner increases up to count, but again, only one question view shows up. When I change things up, I get a lot of null pointers around my <code>TableLayout</code>, so I have removed that portion. </p>
  
  <p>Ultimately, <code>EconFragment</code>'s xml has a Table Layout with a <code>ScrollView</code> which has another <code>TableLayout</code>, questionContainer. </p>
  
  <p><strong>I had hoped originally to add each question view as a row in <code>questionContainer</code>, but that's giving me all sorts of trouble. I posit that it's somewhat related to calling <code>populateQuestions()</code> prior to the return statement in <code>onCreateView()</code>?</strong></p>