我确信这很容易做但我被卡住....我全神贯注地想找到一种方法来填充Xamarin Android中的列表视图。 这是我的代码:
public class MainActivity : Activity { WipService.BasicHttpBinding_IWipService client; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button getsomebtn = FindViewById<Button>(Resource.Id.GetSomeBtn); ListView applist = FindViewById<ListView>(Resource.Id.AppList); getsomebtn.Click += Getsomebtn_Click; } private void Getsomebtn_Click(object sender, EventArgs e) { client = new WipService.BasicHttpBinding_IWipService(); client.GetWorkerListCompleted += Client_GetWorkerListCompleted; client.GetWorkerListAsync(); } public void Client_GetWorkerListCompleted(object sender, WipService.GetWorkerListCompletedEventArgs e) { var x = e.Result; }
WCF服务工作得很好!!!我得到“x”中的列表,见下图。
我的问题是如何填充我的ListView,名为applist ???
答案 0 :(得分:0)
在Xamarin android中,你不能像在Xamarin表单中那样填充listviews。您必须使用ListViewAdaptor。
这是一个例子,
var items = new string[] { "Vegetables","Fruits","Flower Buds","Legumes","Bulbs","Tubers" };
var adapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, items);
applist.Adapter = adapter;
Xamarin有很棒的教程。 Please read。