Question

I am developing an application which has about 8000 names of the cities of India. And when the user types in i use auto complete to help the user to do the job. But some city names have spelling which is hard to guess for people from other states. So we need a approximate string matching for auto complete rather than exact matching which comes by default.

For example there are names like

  • Thirumayilai
  • Thirunettur
  • Thiruthuraiyur
  • Thiruvarur

And also

  • Tirunelveli
  • Tirumangalam

If a user search for the city 'Tirunelveli' But types in text box as 'Thirunel' the autocompletetextview doens't show the name and it does a exact string match.

What should i do to get approximate matching strings in the auto complete drop down list..

Was it helpful?

Solution 2

After alot of search and experiments i found the solution myself..

To do custom string matching we need a custom array adapter which we need to extend ArrayAdapter class and write our own string matching algorithm.

We need to overide getFilter method of ArrayAdapter class for this functionality and add getItem and getCount methods to our custom adapter class.

OTHER TIPS

You need to Create a Custom ArrayAdapter with a Custom Filter (which filter's based on Lexographic Distance being less than a certain threshold (say 3)) which you need return in the getFilter() method of you Adapter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top