在 Android Xamarin 中创建 List<String>

Eri*_*rik 4 c# android for-loop list dynamic

我正在构建一个 android 应用程序,我需要在其中创建一个简单的字符串项目列表,然后我将为列表中的每个项目添加一个特定的控件。

这是我要创建的列表:

List<String> projects = new List<String>(); // How?
Run Code Online (Sandbox Code Playgroud)

我正在尝试的代码:

String projects = new string[] { "hey","yo","app","xamarin","c","xaml" };
Run Code Online (Sandbox Code Playgroud)

我需要计算项目,像这样:

int amount = projects.Count(); // Can I do this?
Run Code Online (Sandbox Code Playgroud)

然后为列表中的每个项目添加控件

// Add the tiles, one by one
for (int i = 0; i < amount; i++)
{
  // Inflate the tile
  var tile = LayoutInflater.Inflate (Resource.Layout.Tile, null);

  // Set its attributes
  tile.FindViewById<TextView> (Resource.Id.projectName).Text = currentProject;

  // Add the tile
  projectScrollView.AddView (tile);
}
Run Code Online (Sandbox Code Playgroud)

“currentProject”字符串是从 SharedPreferences 中检索到的,只是还没有那么远

Jor*_*sys 6

   var projects = new List<String>() { "hey","yo","app","xamarin","c","xaml" };
Run Code Online (Sandbox Code Playgroud)