加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在Android Xamarin中创建列表

发布时间:2020-12-16 01:59:59 所属栏目:百科 来源:网络整理
导读:我正在构建一个 Android应用程序,我需要创建一个简单的String项列表,然后我将为列表中的每个项添加一个特定的控件. 这是我要创建的列表: ListString projects = new ListString(); // How? 我正在尝试的代码: String projects = new string[] { "hey","yo"
我正在构建一个 Android应用程序,我需要创建一个简单的String项列表,然后我将为列表中的每个项添加一个特定的控件.

这是我要创建的列表:

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

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

解决方法

var projects = new List<String>() { "hey","xaml" };

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读