Cheers John, glad it helped. I did bang it out pretty quick - that second Java.Lang.Object loop is a little dodgy ~ there may be ways to clean that up ~ but otherwise you get the idea. Glad i could squeeze linq in too... yay for #monodroid ;-) Thanks for passing it on to the list - not sure why my email didn't go thru... at least you got it! :-\ cd
On Sat, Apr 21, 2012 at 8:45 PM, John Murray <j...@murray.gb.com> wrote: > Though it's not popped up here for some reason Craig Dunn answered my > question and in only a matter of an hour I've got a really good working > solution > > the example you pointed to Jonathan is the standard autocomplete - as far > as > I can see it only searches in the adapter in an ordinal way - i.e Ar - > finds Arizona > but sometimes you want to search the adapter in a way which finds any > string > containing "ar" so the result might be > Arizona > Karachi > (strange bedfellows I know :-) > > To do this you need to customise the adapter > > I was trying to customise some example I found in Java but as always got > stuck on converting the java > > Craig has already done it and posted it on GitHub > Its Xamarin-Monodroid-samples-0cd9b3e > The sub project called content controls > You have to add the custom adapter - > > Here are Craig's links > https://github.com/xamarin/monodroid-samples/tree/master/ContentControls > And add the .cs at https://gist.github.com/2433227 > > but I found it easier to create a new project and just add the custom > adapter because this git hub example also deals with mapping and you can't > compile it unless you have a googlemaps api key > > Just create simple new project and a form with autocompletetextview - > populate a string array and pass it to this code > Note that the custom adapter takes a simple string[] array > ///////////THANKS craig -absolutely cracking solution hope this helps > someone else > > John M > > using System; > using System.Collections.Generic; > using System.Linq; > using Android.App; > > using Android.Views; > using Android.Widget; > > namespace ACBContains { > 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(); > } > } > } > } > > > > > -----Original Message----- > From: monodroid-boun...@lists.ximian.com > [mailto:monodroid-boun...@lists.ximian.com] On Behalf Of Jonathan Pobst > Sent: 05 January 2012 21:46 > To: Discussions related to Mono for Android > Subject: Re: [mono-android] AutoCompleteTextView > > Not sure exactly what you are trying to do, but we have this code here: > > > https://github.com/xamarin/monodroid-samples/blob/master/ApiDemo/Tutorials/A > utoCompleteTutorial.cs > > Jonathan > > > On 1/5/2012 3:32 PM, Tom Opgenorth wrote: > > I've use this before (in Java). Has anybody tried to out with M4A and > > would be willing share a sample/snippet? > > > > > > > > -- > > http://www.opgenorth.net > > > > > > > > _______________________________________________ > > 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 > > _______________________________________________ > 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