Xamarin.Android:无法从“ System.Collections.Generic.List <字符串>”转换为“ [namespace_name] .Item []”

时间:2018-10-26 09:24:21

标签: c# sql visual-studio xaml xamarin.android

我正在尝试将从外部sql服务器接收的数据分配给ListView

(Xamarin.Android):

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/listView3" />

之前的活动如下:

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.layout1);

        var lv = FindViewById<ListView>(Resource.Id.listView3);

        lv.Adapter = new ArrayAdapter<Item>(this, Android.Resource.Layout.SimpleListItem1, Android.Resource.Id.Text1, BaseData.GetEmployees());
        lv.ItemClick += OnItemClick;
    }

    void OnItemClick(object sender, AdapterView.ItemClickEventArgs e)
    {
        int position = e.Position; // e.Position is the position in the list of the item the user touched

        var intent = new Intent(this, typeof(DetailsActivity));

        intent.PutExtra("ItemPosition", position);

        StartActivity(intent);
    }

和Get-Method是:

    public static List<String> GetEmployees()
    {
        List<String> list = new List<String>();

        string sql = "SELECT * FROM adressen";

        using (SqlConnection con = new SqlConnection(connectionString))
        {
            con.Open();

            using (SqlCommand cmd = new SqlCommand(sql, con))
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(reader.GetString(0));
                    }
                }
            }

            con.Close();

            return list;
        }
    }

数据库中的列包含简单的字符串。

不幸的是,我从BaseData.GetEmployees()(活动第8行)收到以下错误消息:

  

无法从“ System.Collections.Generic.List”转换为“ GroceryList.Item []”。

任何人都可以告诉我问题出在哪里以及如何解决此问题,以便正确显示数据库中的数据?

提前感谢一切

最诚挚的问候

0 个答案:

没有答案