2016-09-06 77 views
-1

我相信這是很容易做的,但我卡住....我期待各地找到一種方法來填充Xamarin Android中的列表視圖。 這是我的代碼:如何填充列表視圖Xamarin使用WCF服務

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 ???

回答

0

在Xamarin android中,您不能像在Xamarin表單中那樣填充列表視圖。你必須使用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

+0

你得幫我...我知道你想讓我讀,但這沒有道理。 'var items = new string [] {e.result}' – IMAK

+0

本教程的哪些內容沒有意義?什麼是'e.result'類型?它是一個字符串嗎? –

+0

它是一個列表...看到最後一個圖像 – IMAK