2011-04-24 8 views
0

J'essaie d'afficher la liste après un appel de service Web asynchrone, mais pour une raison quelconque, ce code échoue .... Des suggestions? En ce moment, il bloque simplement l'application.Appel de service Web MonoDroid Async

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

using Android.App; 
using Android.Content; 
using Android.OS; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 
using Test.MyWeb; 

namespace Test 
{ 
    [Activity(Label = "Favorites")] 
    public class FavoritesActivity : ListActivity 
    { 
     private ProgressDialog d; 
     private TextView tv; 
     protected override void OnCreate(Bundle bundle) 
     { 

      base.OnCreate(bundle); 

      d = new ProgressDialog(this); 
      d.SetTitle("Loading..."); 
      d.SetMessage("Please wait..."); 
      d.SetIcon(Resource.Drawable.chef_icon); 
      d.Show(); 



      Test.MyWeb.Daedalus Service = new Daedalus(); 

      Service.getCategoriesCompleted += Service_OnComplete; 
      Service.getCategories(); 


     } 

     private void Service_OnComplete(object s, getCategoriesCompletedEventArgs e) 
     { 

      try 
      { 
       d.Hide(); 

       List<Test.MyWeb.CATEGORY> Categories = e.Result.ToList(); 
       List<string> cats = new List<string>(); 

       foreach (Test.MyWeb.CATEGORY Item in Categories) 
       { 
        cats.Add(Item.NAME); 

       } 

       ListAdapter = new ArrayAdapter<string>(this, Resource.Layout.Favorites, cats); 

       ListView.TextFilterEnabled = true; 

       ListView.ItemClick += delegate(object sender, ItemEventArgs args) 
       { 
        // When clicked, show a toast with the TextView text 
        Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short). 
         Show(); 
       }; 



      } catch(Exception ex) 
      { 
       Toast.MakeText(this, ex.Message, ToastLength.Short).Show(); 

      } 
     } 

    } 
} 

Répondre