I just wanna display my data in list view but i am not finding the solution, in unity how can we create list view..???

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

3

There 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();
	}
}

@phort99: thanx for ur reply can u please explain with some example, actually i also tried GUILayout thing but not getting my solution.

I added some sample code.

@phort99 thanks it helps me alot.. :)

Feel 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

its possible to generate this items dynamic… to make something like this:

the items row Heiht, its different to header row…

Sorry for my english :frowning:

Our product, “ListView for Unity UI”, is a ListView control that uses the same code interface as the .NET control.
Check it out here!