Q:

How to create a basic listview in unity

I need to create a basic list view or scroll view in my scene in the game development engine, Unity.

I just beginning to learn Unity. 
I have attempted to create a list view without success.
I have a set of strings which I need to display like a list view or scroll view.
One below the other, I have entered the strings in to a List<string> now.

Now what am doing is set the string to display directly with the new line character, \n.
I also tried adding the strings to the content of scroll view in unity, but I have not managed to get it working.
Can anyone please provide a reference?

A:

The "easiest" and most elegant way I can think about is using a Vertical Layout Group

Add a new empty gameobject under your canvas
Set the desired dimensions using the RectTransform component
Attach the "Vertical Layout Group" component
In your code, for each string in your list :

Create a new GameObject :
Attach a text component to it
Fill the text attribute with your string
Set the parent of the transform to be the first empty gameobject in 1st step

Here is a piece of code I haven't tested :
// Drag & Drop the vertical layout group here
public UnityEngine.UI.VerticalLayoutGroup verticalLayoutGroup ;

// ... In your function
RectTransform parent = verticalLayoutGroup.GetComponent<RectTransform>() ;
for( int index = 0 ; index < stringList.Count ; ++index )
{
     GameObject g = new GameObject( stringList[index] ) ;
     UnityEngine.UI.Text t = g.AddComponent<UnityEngine.UI.Text>();
     t.addComponent<RectTransform>().setParent( parent ) ;
     t.text = stringList[index] ;
}

If you need more customization, you can instantiate a prefab instead of manually create the texts gameobjects.

