I've a linear layout in a fragment. How to dynamically add a view to it from the activity?
<p>I'm posting data from one fragment and updating the other fragment by adding a view to it. I'm not using listView. I am using LinearLayout. </p>

<p>I've a very simple doubt. How do I get the view and update it by adding another view to it? </p>

<p>Basically I want to inflate the linearlayout that already has the data and add a view to it in the main activity that adds the fragment.</p>

<p>Edit: </p>

<pre><code>LinearLayout ll = (LinearLayout)fragment.getView().findViewById(R.id.commentFragmentLayout);
            ViewGroup view = (ViewGroup) ll.getParent();
            View customView = view;



            TextView   commentContext  = (TextView) customView.findViewById(R.id.commentText);

            commentContext.setText("hello");


            view.addView(customView);
</code></pre>

<p>I tried to do that in the main activity but my view gave null pointer exception.</p>

<p>Edit 2: </p>

<pre><code>   FragmentManager fm       = getSupportFragmentManager();
                // You can find Fragments just like you would with a View by using FragmentManager.
                android.support.v4.app.Fragment fragment = fm.findFragmentById(R.id.fragmentCommentContent); 
                LayoutInflater inflater = (LayoutInflater)   getApplicationContext().getSystemService(getApplicationContext().LAYOUT_INFLATER_SERVICE);
                View child = inflater.inflate(R.layout.comments_list_item, null);


            LinearLayout ll = (LinearLayout)fragment.getView().findViewById(R.id.commentFragmentLayout);
            TextView    newText  = (TextView) child.findViewById(R.id.commentText);
            newText.setText("Important text");
            ll.addView(newText);
</code></pre>

<p>I tried that and got : The specified child already has a parent. Call removeView() on child's parent first. The problem is, if I call remove view, I lose the previous data that I've inserted in the layout. </p>
