0
    LinearLayout  lay1 = (LinearLayout) findViewById(R.id.lay1);

        for(int i=0;i<list1.size();i++) {

                           View child = lay1.getChildAt(i);
                         LinearLayout  lay3 = (LinearLayout) child.findViewById(R.id.lay3);

                           for (j = 0; j <list2.size(); j++) {
                               View child1 = lay3.getChildAt(j);
      //                         View hiddenInfo11 = getActivity().getLayoutInflater().inflate(R.layout.add_inner_item, lay3 , false);
                               final TextView name = (TextView) child1.findViewById(R.id.name);
                               name.setText("new");
                           }
                       }

XML Layout:

                        <LinearLayout
                            android:id="@+id/lay1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="4dp"
                            android:orientation="horizontal">


                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/lay2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="4dp"
                            android:background="@color/white"
                            android:orientation="horizontal">

                        </LinearLayout>

add_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">


    <LinearLayout
        android:id="@+id/lay3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="vertical">

    </LinearLayout>


</LinearLayout>

add_inner_item.Xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >

    <TextView android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

</LinearLayout>

Added View Dynamically using the following method.

  for(int i=0;i<list.size();i++) {
                    View hiddenInfo = getActivity().getLayoutInflater().inflate(R.layout.add_item, lay, false);
                    LinearLayout lay3 = (LinearLayout) hiddenInfo.findViewById(R.id.lay3);
                    lay1.addView(hiddenInfo);

                    for (j = 0; j < list2.size(); j++) {


                            View hiddenInfo1 = getActivity().getLayoutInflater().inflate(R.layout.add_inner_item, lay3, false);

                            final TextView name = (TextView) hiddenInfo1.findViewById(R.id.name);


                            name.setText(list2.get(j).get("Name"));

                            lay3.addView(hiddenInfo1);

                    }

I have one Layout with creating dynamically and I want to update the child textview from outside of the button click view.I have tried this code.But nothing is changed.Can anyone give suggestion to this sample.

rajeshlawrance
  • 549
  • 2
  • 6
  • 25
  • you write this code onClick of your button? – Anjali Nov 17 '15 at 12:48
  • yes.inside the button click i wrote this code. – rajeshlawrance Nov 17 '15 at 12:49
  • i created the view successfully.But i am unable to update the child textview. Actually the view is not called. – rajeshlawrance Nov 17 '15 at 12:50
  • where you define your textview? you haven't mention it in your xml? please post your activity code – Anjali Nov 17 '15 at 12:51
  • Could you post the code where you add the TextViews to your Layouts? I am actually a little bit confused about the code structure. Why don't you just add an a Listener to every child which just handles its childs. I don't see a reason for iterating over each child. – daemmie Nov 17 '15 at 12:53
  • Hi Where you add textviews ? And How you give Name to these textViews ? – Syed Qasim Ahmed Nov 17 '15 at 12:54
  • I have two arraylist "list1 and list2". Based on List1 size, the textview created in child layout with list2 arraylist.This is totally dynamic layout,that's why i created. – rajeshlawrance Nov 17 '15 at 12:55

1 Answers1

1

You are looking for "lay2" inside the "lay1" container. According to your XML layout, they are not nested, so you won't be able to find it this way. Change it to this:

LinearLayout  lay2 = (LinearLayout) findViewById(R.id.lay2);

You should get the actual lay2 container. I'm not sure whether the text views are there though since I have seen your code for the views' creation.

EDIT:

I've not specified a parent - you should use the Activity for this. Something like:

LinearLayout  lay2 = (LinearLayout) MyActivity.this.findViewById(R.id.lay2);
Samuil Yanovski
  • 2,837
  • 17
  • 19
  • I've added a few more details - check it up and let me know if it works. :) – Samuil Yanovski Nov 17 '15 at 13:15
  • Can you include all the xml layouts (the fragment's one, add_item, add_inner_item). One of them seems to be missing. – Samuil Yanovski Nov 17 '15 at 13:50
  • hm, looking at your edits, everything looks fine. Could you verify that the code you've posted (without my changes) is not working. If this is the case, can you debug the application and check if it goes into the FOR cycles at all. – Samuil Yanovski Nov 17 '15 at 17:03