title: Custom Arrayadapter with Custom Filter
body: <p>I will give you a short review about what i'm trying to do:
  I want to fill the DropDown of a AutoCompleteTextView with my own Objects. those objects contain 3 Strings. In the list_item_view should be 2 of the strings. This List should be filterable.</p>
  
  <p>Now a bit of code, what i've done till now:</p>
  
  <p>My CustomAdapter looks like this:</p>
  
  <pre><code>public class CustomerAdapter : ArrayAdapter&lt;CustomerSingle&gt;, IFilterable
  {
      private ws_test.Test ws=null;
      public static List&lt;CustomerSingle&gt; _contactList;
      private Activity _activity;
      private CustomerAdapterFilter filter = null;
  
      public CustomerAdapter(Activity activity, Context context,int resourceId)//List&lt;CustomerSingle&gt; assets)
      :base(context,resourceId)//,assets)
      {
          _activity = activity;
          ws=new ws_test.Test();
          _contactList = new List&lt;CustomerSingle&gt;();
      }
  
      public static List&lt;CustomerSingle&gt; getCustomerList()
      {
          return _contactList;
      }
  
      public void Add(CustomerSingle item)
      {
           _contactList.Add(item);
      }
  
      public override int Count
      {
          get { return _contactList.Count; }
      }
  
      public override long GetItemId(int position)
      {
          return _contactList[position].id;
      }
  
      public override View GetView(int position, View convertView, ViewGroup parent)
      {
          var view = convertView ?? _activity.LayoutInflater.Inflate(Resource.Layout.details, parent, false);
          var contactName = view.FindViewById&lt;TextView&gt;(Resource.Id.Name);
          var contactAddress = view.FindViewById&lt;TextView&gt;(Resource.Id.Address);
          contactName.Text = _contactList[position].name;// +"\n" + _contactList[position].address;
          contactAddress.Text = _contactList[position].address;
  
          return view;
      }
  
      public override Filter Filter
      {
          get
          {
              return new CustomerAdapterFilter();
          }
      }
  
      public override void NotifyDataSetChanged()
      {
          base.NotifyDataSetChanged();
      }
  
      public override void NotifyDataSetInvalidated()
      {
          base.NotifyDataSetInvalidated();
      }
  }
  </code></pre>
  
  <p>The CustomerSingle looks like this:</p>
  
  <pre><code>public class CustomerSingle
  {
      public string no { get; set; }
      public string name { get; set; }
      public string address { get; set; }
      public int id { get; set; }
  
      public CustomerSingle(string no, string name, string address, int id)
      {
          this.address = address;
          this.name = name;
          this.no = no;
          this.id = id;
      }
  }
  </code></pre>
  
  <p>Ok, now I need an own Filter what i'm trying to do here:</p>
  
  <pre><code>public class CustomerAdapterFilter:Filter
  {
      protected object mLock = new object();
      protected List&lt;CustomerSingle&gt; mOriginalValues = null;
  
      protected override FilterResults PerformFiltering(Java.Lang.ICharSequence prefix)
      {
  
          FilterResults results = new FilterResults();
          if (mOriginalValues == null) {
              lock(mLock) {
                  mOriginalValues = new List&lt;CustomerSingle&gt;(CustomerAdapter._contactList);
  
              }
          }
  
          if (prefix == null || prefix.Length() == 0) {
              lock (mLock) {
                  List&lt;CustomerSingle&gt; list = new List&lt;CustomerSingle&gt;(mOriginalValues);
                  IntPtr listptr = list.
                  results.Values = list;
                  results.Count = list.Count;
              }
          } else {
              String prefixString = prefix.ToString().ToLowerInvariant();
  
              List&lt;CustomerSingle&gt; values = mOriginalValues;
              int count = values.Count;
  
              List&lt;CustomerSingle&gt; newValues = new List&lt;CustomerSingle&gt;(count);
  
              for (int i = 0; i &lt; count; i++) {
                  CustomerSingle value = values.ElementAt(i);
                  String valueText = value.ToString().ToLowerInvariant();
  
                  // First match against the whole, non-splitted value
                  if (valueText.StartsWith(prefixString)) {
                      newValues.Add(value);
                  } else {
                      String[] words = valueText.Split(' ');
                      int wordCount = words.Length;
  
                      for (int k = 0; k &lt; wordCount; k++) {
                          if (words[k].StartsWith(prefixString)) {
                              newValues.Add(value);
                              break;
                          }
                      }
                  }
              }
  
              results.Values = (Object) newValues;
              results.Count = newValues.Count;
          }
  
          return results;
      }
  
      protected override void PublishResults(Java.Lang.ICharSequence constraint, Filter.FilterResults results)
      {
          //noinspection unchecked
          var mObjects = results.Values;
          if (results.Count &gt; 0)
          {
              NotifyDataSetChanged();
          }
          else
          {
              notifyDataSetInvalidated();
          }
      }
  }
  </code></pre>
  
  <p>My problem is, I can't Convert from Java.Lang.Object to my CustomerSingle... Does someone have an Idea?</p>
  
  <p>Thank you!</p>
  
  <p>Update: I changed to JavaList in the filter and did the extension to Java.Lang.Object at the CustomerSingle</p>