title: Dynamic views not displaying in fragment: android
body: <p>I have a ScrollView with a child LinearLayout. I am programmatically adding TextViews and NumberPickers to the LinearLayout through a separate View method. However the dynamic objects do not display when the tab containing the ScrollView is clicked.</p>
  
  <p>Here is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
    View rootview = inflater.inflate(R.layout.activity_settings_tab, container, false);
    super.onCreate(savedInstanceState);
    myDb = new DatabaseHelper(getContext());
  
    rootview.findViewById(R.id.scroll_config);
    viewFunds();
    return rootview;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is the separate method I have mentioned that dynamically adds objects to the LinearLayout:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public View viewFunds(View rootview) {
  
    ScrollView scrollView = new ScrollView(getActivity());
    scrollView.findViewById(R.id.scroll_config);
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.findViewById(R.id.ll_config);
    //final View linearLayout = getActivity().findViewById(R.id.ll_config);
    linearLayout.removeAllViews(); //clear layout first - LINE WITH ISSUE
    linearLayout.setGravity(Gravity.CENTER);
  
    LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    LinearLayout.LayoutParams lp3 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  
    //create dynamic objects inside scrollview and dynamic linear layout - horizontal
    for (int i = 0; i &lt; res2.getCount(); i++) {
      LinearLayout llh = new LinearLayout(getActivity());
      llh.setOrientation(LinearLayout.HORIZONTAL);
      LinearLayout.LayoutParams lp_llh = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      llh.setLayoutParams(lp_llh);
  
      linearLayout.addView(llh);
  
      NumberPicker numberPicker = new NumberPicker(getActivity());
      numberPicker.setMinValue(0);
      numberPicker.setMaxValue(100);
      LinearLayout.LayoutParams lp_np = new LinearLayout.LayoutParams(70, LinearLayout.LayoutParams.WRAP_CONTENT);
      numberPicker.setLayoutParams(lp_np);
      numberPicker.setGravity(Gravity.CENTER_HORIZONTAL);
  
      //showMessage("value",res2.getString(3));
      numberPicker.setValue(Integer.parseInt(res2.getString(2))); //
      TextView textView = new TextView(getActivity());
      textView.setText( /*textArray[i] + " " +*/ res2.getString(1));
  
  
      llh.addView(textView);
      linearLayout.addView(numberPicker);
  
    }
    return scrollView;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>What am I doing wrong here?</p>