I am using web service for showing data through an API my data is loading properly and showing in console but i need listview to show it on GUI. Please help and thanks in advance
3 Answers
3There is no API for creating an iOS style list view. If you need a real iOS list view, you could use a native plugin. If you just want to display some information in a list with Unity’s GUI, GUILayout is your friend. Create a scroll view, and add labels or buttons or whatever you need.
Here’s some sample code:
using UnityEngine;
using System.Collections;
public class listView : MonoBehaviour {
Vector2 scrollPosition = Vector2.zero;
void OnGUI () {
string[] listItems =
{
"Hello world,",
"this",
"is a",
"very",
"very",
"very",
"very",
"very",
"very",
"long",
"list.",
};
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)
{
GUILayout.Label(item, GUI.skin.box, GUILayout.ExpandWidth(true));
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndArea();
}
}
its possible to generate this items dynamic… to make something like this:
- http://pic002.cnblogs.com/images/2011/31770/2011060717220256.png
- https://lh4.ggpht.com/bjwAAE72H5znXX8L3MgOGKMyOCVjc7DgyRQGPqLqSKrkbiAowtWKy98EbwgHefiW1wQ=h900
the items row Heiht, its different to header row…
Sorry for my english ![]()
Our product, “ListView for Unity UI”, is a ListView control that uses the same code interface as the .NET control.
Check it out here!
@phort99: thanx for ur reply can u please explain with some example, actually i also tried GUILayout thing but not getting my solution.
– rishabhvinodI added some sample code.
– phort99@phort99 thanks it helps me alot.. :)
– rishabhvinodFeel so fortunate, the fine answer here helped me a lot on solving the problem with [listview control][1] I am facing with. Since I am quite new in Unity and know nothing about listview, I read through a [listview control tutorial][2] but still got no idea. This question and its answer did me a great favor. But, still can't be clear with the native plug-in thing. [1]: http://www.kettic.com/winforms_ui/listview.shtml [2]: http://www.kettic.com/winforms_ui/csharp_guide/listview_get_started.shtml
– Uchiha_Itachi