代码之家  ›  专栏  ›  技术社区  ›  Arfmann

Xamarin ArrayAdapter不适用于int[]

  •  1
  • Arfmann  · 技术社区  · 7 年前

    我有一个带有阵列适配器的listview。我需要在该列表视图中显示一个int[],但它只适用于字符串[]。有什么想法吗?

    int[] a = new int[20];
    
    ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, a[i]);
    
    ListView list = FindViewById<ListView>(Resource.Id.listView1);
    list.Adapter = adapter;
    

    这个 int i 正在进行一个周期。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Sajeetharan    7 年前

    可以转换为字符串数组,

    string[] result = a.Select(x=>x.ToString()).ToArray();
    
    ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, result[i]);
    
        2
  •  0
  •   SushiHangover    7 年前

    使用 IList -基于集合,允许自动进行C#/Java类型转换

    var a = new List<int>() { 1,2,3 };
    var adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, a);
    ListView list = FindViewById<ListView>(Resource.Id.listView1);
    list.Adapter = adapter;