如何使用WCF服务填充列表视图Xamarin

时间:2016-09-06 00:20:01

标签: c# android wcf listview xamarin.android

我确信这很容易做但我被卡住....我全神贯注地想找到一种方法来填充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”中的列表,见下​​图。

As you can see I can see the details of the worker

我的问题是如何填充我的ListView,名为applist ???

1 个答案:

答案 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