John, I've put something together quickly that slots into the existing ContentControls<https://github.com/xamarin/monodroid-samples/tree/master/ContentControls>[0] sample on github. here it is in action, searching for "ea" in a dictionary http://screencast.com/t/7rWbUaVY
Download that sample,then in the Screens/AutoCompleteTextViewScreen.cschange the adapter to use act.Adapter = new AutoAdapter(this, Android.Resource.Layout.SimpleDropDownItem1Line, wordlist); and add this AutoAdapter.cs class/file (also at https://gist.github.com/2433227) using System; using System.Collections.Generic; using Android.App; using Android.Views; using Android.Widget; namespace ContentControls { public class AutoAdapter : ArrayAdapter, IFilterable { LayoutInflater inflater; Filter filter; Activity context; public string[] AllItems; public string[] MatchItems; public AutoAdapter (Activity context, int txtViewResourceId, string[] items) : base(context, txtViewResourceId, items) { inflater = context.LayoutInflater; filter = new SuggestionsFilter(this); AllItems = items; MatchItems = items; } public override int Count { get { return MatchItems.Length; } } public override Java.Lang.Object GetItem (int position) { return MatchItems[position]; } public override View GetView (int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) view = inflater.Inflate(Android.Resource.Layout.SimpleDropDownItem1Line, null); view.FindViewById<TextView>(Android.Resource.Id.Text1).Text = MatchItems[position]; return view; } public override Filter Filter { get { return filter; } } class SuggestionsFilter : Filter { AutoAdapter a; public SuggestionsFilter (AutoAdapter adapter) : base() { a = adapter; } protected override Filter.FilterResults PerformFiltering (Java.Lang.ICharSequence constraint) { FilterResults results = new FilterResults(); if (constraint != null) { var searchFor = constraint.ToString (); Console.WriteLine ("searchFor:" + searchFor); var matchList = new List<string>(); var matches = from i in a.AllItems where i.IndexOf(searchFor) >= 0 select i; foreach (var match in matches) { matchList.Add (match); } a.MatchItems = matchList.ToArray (); Console.WriteLine ("resultCount:" + matchList.Count); Java.Lang.Object[] matchObjects; matchObjects = new Java.Lang.Object[matchList.Count]; for (int i = 0; i < matchList.Count; i++) { matchObjects[i] = new Java.Lang.String(matchList[i]); } results.Values = matchObjects; results.Count = matchList.Count; } return results; } protected override void PublishResults (Java.Lang.ICharSequence constraint, Filter.FilterResults results) { a.NotifyDataSetChanged(); } } } } HTH craig [0] https://github.com/xamarin/monodroid-samples/tree/master/ContentControls On Sat, Apr 21, 2012 at 7:59 AM, John Murray <j...@murray.gb.com> wrote: > I have looked at the forum but cant find any assistance with this > previously – Might be useful to others **** > > ** ** > > I was looking for a way to run an autocompletetextbox with a filter which > allowed the selection from teh adapter to show any items ‘containing’ the > letters typed in (by default it will filter on anything ‘beginning’ with > the letters typed in ) **** > > ** ** > > I came across an item on StackOverflow with this Java code **** > > I have successfully converted java code before but htis one beats me -Can > anyone help – Like I say this might be a useful example to add to the > Webote or one of the books to help others – I’m just not knowledgeable > enough to solve it **** > > This code is my attempt at conversion but throws up several errors which I > cant figure**** > > ** ** > > I realise that even if I get this translated into c# I still have to > figure how to filter on a ‘contains’ model rather than ‘begin wth’ **** > > Any help much appreciated **** > > ** ** > > John Murray**** > > ** ** > > Agar14.ACAdapter.SuggestionsFilter' does not implement inherited abstract > member 'Android.Widget.Filter.PerformFiltering(Java.Lang.ICharSequence)'** > ** > > 'Agar14.ACAdapter.SuggestionsFilter.PerformFiltering(Android.Runtime.CharSequence)': > no suitable method found to override**** > > 'Agar14.ACAdapter.SuggestionsFilter.PublishResults(Android.Runtime.CharSequence, > Android.Widget.Filter.FilterResults)': no suitable method found to > override **** > > Cannot access a non-static member of outer type > 'Android.Widget.BaseAdapter' via nested type > 'Agar14.ACAdapter.SuggestionsFilter' **** > > 'Android.Runtime.CharSequence': static types cannot be used as > parameters **** > > ** ** > > public class ACAdapter : ArrayAdapter , IFilterable **** > > {**** > > protected LayoutInflater mInflater;**** > > protected Filter filter;**** > > public ACAdapter(Context context, int textViewResourceId, string[] > items) :base(context, textViewResourceId, items)**** > > {**** > > **** > > SuggestionsFilter filter = new SuggestionsFilter();**** > > mInflater = LayoutInflater.From(context);**** > > }**** > > public override View GetView(int position, View convertView, > ViewGroupparent) { > **** > > View v = convertView;**** > > if (v == null) {**** > > v = mInflater.Inflate(Resource.Layout.list_item, parent, false > );**** > > }**** > > ** ** > > TextView tt = v.FindViewById<TextView>(Resource.Layout.textview);* > *** > > tt.SetText("Suggestion item",TextView.BufferType.Editable);**** > > return v;**** > > }**** > > ** ** > > public Filter GetFilter() {**** > > return filter;**** > > }**** > > public class SuggestionsFilter : Filter {**** > > protected override FilterResults > PerformFiltering(CharSequenceconstraint) { > **** > > return null;**** > > }**** > > protected override void PublishResults(CharSequence constraint, > FilterResults results) {**** > > NotifyDataSetChanged();**** > > }**** > > }**** > > }**** > > ** ** > > ** ** > > ** ** > > _______________________________________________ > Monodroid mailing list > Monodroid@lists.ximian.com > > UNSUBSCRIBE INFORMATION: > http://lists.ximian.com/mailman/listinfo/monodroid > >
_______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid