how to show data in same gui layout..??

I am showing data in my list view like this…

void OnGUI () {

   GUILayout.BeginArea(new Rect(0f, 0f, 300f, 200f), GUI.skin.window);
   scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true); 
   GUILayout.BeginVertical(GUI.skin.box);

   foreach (string item in listItems)
   {
   
     if(GUILayout.Button(item, GUI.skin.box, GUILayout.ExpandWidth(true)))
		
		{ 
            StartCoroutine(selectSecondRequest(obj[item]));
                GUILayout.BeginArea(new Rect(0f, 0f, 300f, 200f), GUI.skin.window);
   				scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true); 
   				GUILayout.BeginVertical(GUI.skin.box);
			
				foreach (string item1 in listItems1){
				
					if(GUILayout.Button(item1, GUI.skin.box, GUILayout.ExpandWidth(true)))
					{
						Debug.Log(item1+ "  " + obj[item1]);
					}
				}
	
			GUILayout.EndVertical();
   			GUILayout.EndScrollView();
   			GUILayout.EndArea();
        }

   }
   GUILayout.EndVertical();
   GUILayout.EndScrollView();
   GUILayout.EndArea();
}

now i am trying to show data from my another xml on click in same layout but i am not able to do this thing…
please any one help me… where i am doing wrong…

thanks in advance…

I guess that the coroutine you’re calling prepares listItems1 collection, which is global. If yes, then you need to remove all the code except StartCoroutine from ‘if’ statement, and move inner ‘foreach’ loop after outer ‘foreach’ loop. You don’t need to include additional GUILayuot Begin and End parts, if you need new buttons to be shown in the same layout.

Modified code:

foreach (string item in listItems)
{
    if (GUILayout.Button(item, GUI.skin.box, GUILayout.ExpandWidth(true)))
    {
        StartCoroutine(selectSecondRequest(obj[item]));
    }
}

if (listItems1 != null)
{
    foreach (string item1 in listItems1)
    {
        if (GUILayout.Button(item1, GUI.skin.box, GUILayout.ExpandWidth(true)))
        {
            Debug.Log(item1 + "  " + obj[item1]);
        }
    }
}