使用c#编码的动态字符串的Listview(Xamarin Mono)

使用c#编码的动态字符串的Listview(Xamarin Mono),c#,android,list,listview,xamarin,C#,Android,List,Listview,Xamarin,我正在努力将我的Windows Forms C#项目转换为Android。 严格来说,填充列表视图会给我带来问题 在Windows项目中,它是小菜一碟: foreach(...){ ... listBox1.Items.Add(res[3] + " | " + res[0] + " | " + lang); ... } (res是由正则表达式填充的字符串列表) 但在安卓系统中,我想这并不容易。 我在主布局中创建了一个列表视图 <ListView android:minWidth=

我正在努力将我的Windows Forms C#项目转换为Android。 严格来说,填充
列表视图
会给我带来问题

在Windows项目中,它是小菜一碟:

foreach(...){
...
listBox1.Items.Add(res[3] + " | " + res[0] + " | " + lang);
...
}
(res是由正则表达式填充的字符串列表)

但在安卓系统中,我想这并不容易。 我在主布局中创建了一个
列表视图

<ListView
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/listView1"
    android:layout_weight="1" />

那么,我该如何正确处理这个问题呢

我不明白为什么要对一个项目使用数组,但处理方法是:

list1.adapter = new ArrayAdapter<string> (this, 
   Android.Resource.Layout.SimpleListItem1, 
   new string[] { temp });
list1.adapter=新的阵列适配器(此,
Android.Resource.Layout.SimpleListItem1,
新字符串[]{temp});

获取单个值,并将其转换为用于列表的数组。与其他方法一样,由于您提供了数据,因此始终可以将其转换为列表所需的格式。

您正在将项目逐个添加到列表框中。使用适配器也一样

var list = new List<string>();

foreach(...){
...
//listBox1.Items.Add(res[3] + " | " + res[0] + " | " + lang);
list.Add(string.Format("{0} | {1} | {2}", res[3], res[0], lang));
...
}

list1.Adapter = new ArrayAdapter<string> (this, 
   Android.Resource.Layout.SimpleListItem1, 
   list.ToArray());
var list=newlist();
foreach(…){
...
//listBox1.Items.Add(res[3]+“|”+res[0]+“|”+lang);
Add(string.Format(“{0}{1}}{2}”,res[3],res[0],lang));
...
}
list1.Adapter=新阵列适配器(此,
Android.Resource.Layout.SimpleListItem1,
list.ToArray());
或者:

var adapter = new ArrayAdapter<string> (this, 
   Android.Resource.Layout.SimpleListItem1);

// uncomment if you want live update
// list1.Adapter = adapter;

foreach(...){
    adapter.Add(string.Format("{0} | {1} | {2}", res[3], res[0], lang));
    // uncomment if you want live update
    // adapter.NotifyDataSetChanged();
}

// comment out if you want live update
list1.Adapter = adapter;
var adapter=new ArrayAdapter(此,
Android.Resource.Layout.SimpleListItem1);
//如果要实时更新,请取消注释
//列表1.适配器=适配器;
foreach(…){
Add(string.Format(“{0}{1}}{2}”,res[3],res[0],lang));
//如果要实时更新,请取消注释
//adapter.NotifyDataSetChanged();
}
//如果您想要实时更新,请将其注释掉
列表1.适配器=适配器;
var list = new List<string>();

foreach(...){
...
//listBox1.Items.Add(res[3] + " | " + res[0] + " | " + lang);
list.Add(string.Format("{0} | {1} | {2}", res[3], res[0], lang));
...
}

list1.Adapter = new ArrayAdapter<string> (this, 
   Android.Resource.Layout.SimpleListItem1, 
   list.ToArray());
var adapter = new ArrayAdapter<string> (this, 
   Android.Resource.Layout.SimpleListItem1);

// uncomment if you want live update
// list1.Adapter = adapter;

foreach(...){
    adapter.Add(string.Format("{0} | {1} | {2}", res[3], res[0], lang));
    // uncomment if you want live update
    // adapter.NotifyDataSetChanged();
}

// comment out if you want live update
list1.Adapter = adapter;