- Home /
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...
Answer by ArkaneX · Sep 06, 2013 at 01:23 PM
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]);
}
}
}
If this fully answers your question, then please accept. If you need any additional explanation, I'll gladly help :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613113658im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
,Roll a ball - project 0 Answers
How to draw an arrow from fps contoller 1 Answer
getting high score of game from asp.net page 2 Answers
Mathf.pingpong 4 Answers