【发布时间】:2014-02-10 17:16:08
【问题描述】:
我正在构建一个 Android 应用程序,我需要在其中创建一个简单的字符串项目列表,然后我将为列表中的每个项目添加一个特定的控件。
这是我要创建的列表:
List<String> projects = new List<String>(); // How?
我正在尝试的代码:
String projects = new string[] { "hey","yo","app","xamarin","c","xaml" };
我需要清点物品,如下所示:
int amount = projects.Count(); // Can I do this?
然后为列表中的每个项目添加控件
// 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);
}
"currentProject" 字符串是从 SharedPreferences 中检索到的,还没有到那么远
【问题讨论】:
-
你有什么问题?
-
@HighCore 听起来像是关于语法的问题
-
这是关于我如何创建一个基本的字符串列表,轻松添加、读取和删除项目并能够对它们进行计数
标签: c# android list dynamic for-loop