For those that have seen and commented on this in the past, I'm still trying
to figure this out. I've trimmed the code from the last posting and am
getting closer (I think). 

This is the error, I'll post the code below the stack trace:
/
05-29 19:47:00.731: E/AndroidRuntime(20277): FATAL EXCEPTION: main
05-29 19:47:00.731: 
E/AndroidRuntime(20277): java.lang.IndexOutOfBoundsException: Invalid index
0, size is 0
05-29 19:47:00.731: 
E/AndroidRuntime(20277):        at
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
05-29 19:47:00.731: 
E/AndroidRuntime(20277):        at java.util.ArrayList.get(ArrayList.java:311)
05-29 19:47:00.731: E/AndroidRuntime(20277):    at
android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
05-29 19:47:00.731: /

When I click the 2nd letter in the autocomplete text view, the
PerformFiltering fires and gets back the suggestions from the web service.
The adapters Count method gets called, but it never makes it to GetItem. The
error happens when control returns from PerformFiltering Method .

public class ContactAdapter : ArrayAdapter<String>, IFilterable
    {
        //public string[] resultsList;
        public List<string> resultsList;

        Filter filter;
        LayoutInflater inflater;
         public ContactAdapter(Activity context, int textViewResourceId)
            : base(context, textViewResourceId)
         {
             inflater = context.LayoutInflater;
             filter = new SuggestionFilter(this);
             global::Android.Util.Log.Warn("Debug.Log", "filter initialized
to sugg filt"); //executes
            
         }

         public override int Count
         {
             get {

                 global::Android.Util.Log.Warn("Debug.Log", "inside count
getter:" + resultsList.Count); //executes
                 return resultsList.Count; 
             }
         }
         public string GetItem(int position)
         {
             global::Android.Util.Log.Warn("Debug.Log", "get item"); //DOES
NOT EXECUTE BEFORE CRASH
             //return resultsList[position];
             return "default item";
         }
         public override long GetItemId(int position)
         {
             return position;
         }

        

         public override Filter Filter
         {
             get
             {
                 return filter;   
             }
         }
         class SuggestionFilter : Filter
         {
            ContactAdapter customAdapter;
            
            public SuggestionFilter(ContactAdapter adapter) 
                : base() 
            {
                                customAdapter = adapter;
                        }
             protected override FilterResults
PerformFiltering(Java.Lang.ICharSequence constraint)
             {
                 global::Android.Util.Log.Warn("Debug.Log", "just inside
performfiltering");
                 FilterResults fr = new FilterResults();
                 List<string> results=new List<string>();
                 
                 if (constraint != null)
                 {
                     results = autocomplete(constraint.ToString());
                     
                     string[] tmpResults =results.ToArray();
                     global::Android.Util.Log.Warn("Debug.Log", "results
count: " +results.Count());  //correct count
                     fr.Values = tmpResults;
                    fr.Count = results.Count();
                 }
                customAdapter.resultsList = results;
                 return fr;
                 //ERROR HAPPENS HERE
             }
             protected override void PublishResults(Java.Lang.ICharSequence
constraint, FilterResults results)
             {
                 global::Android.Util.Log.Warn("Debug.Log", "about to
publish results"); //executes
                 customAdapter.NotifyDataSetChanged();
                 global::Android.Util.Log.Warn("Debug.Log", "published
results");//executes
             }

             private List<string> autocomplete(string p)
             {
                  List<string> data = new List<string>();
                  try
                  {
                      var svcdata =Gateway.GetCompanyContacts(1, 1);
                      foreach (var x in svcdata)
                      {
                          data.Add(x.EmailAddress);
                          global::Android.Util.Log.Warn("Debug.Log", "item
:" + x.EmailAddress); //executes
                          //do something with the keys
                      }
                      global::Android.Util.Log.Warn("Debug.Log", "perf.
filt. after getting data: " + data.Count());//executes
                    
                  }
                  catch (Exception ex)
                  { 
                    //do something
                  }
                  return data;
             }
         }



    }



--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/AutoCompleteTextView-pt-3-tp5713355.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to