如何在Xamarin中使用文本和图像创建ListView?

时间:2015-03-25 07:09:23

标签: c# xamarin xamarin.android

我在Youtube上找到了这个好的教程:https://www.youtube.com/watch?v=WRANgDgM2Zg这正是我想要做的。 无法为Xamarin找到任何东西,所以我决定在Xamarin中试用它

我创建了这样的用户个人资料;

使用System;

namespace ListViewTest
{
    public class UserProfile
    {
        private string name;
        private int ProfileID;
        private int ImageID;

        public UserProfile (string name, int ProfileID, int ImageID)
        {
            this.name = name;
            this.ProfileID = ProfileID;
            this.ImageID = ImageID;
        }

        public string GetName(){
            return name;
        }

        public int GetProfileID(){
            return ProfileID;
        }

        public int GetImageID(){
            return ImageID;
        }

    }
}

但是当试图像这样创建一个实例时:

List<UserProfile> myProfiles = new ArrayList<UserProfile>();

它说“找不到类型或命名空间名称'ArrayList是否缺少using指令或程序集引用?”这个消息出现在ArrayList

我不确定缺少什么?

1 个答案:

答案 0 :(得分:0)

C#中没有类似 ArrayList&lt;&gt; 的内容。意味着没有ArrayList的通用实现。因为在ArrayList中你可以存储任何类型的对象,所以没有提供它的通用含义。

在这种情况下你可以使用

List<UserProfile> myProfiles = new List<UserProfile>();

还建议您将Get方法更改为以下属性:

private string name;
public string Name
{
    get { return name; }
}