I am trying to implement behavior similar to spell check, however not exactly same. By static, I mean only on certain words.
So let's say I have an array of 10 strings.
String[] originalWords = new String[] {
"Apple", "Banana", "Orange", "Pear", "Grape",
"Pineapple", "Lemon", "Mango", "Cherry", "Peach"
};
Now, I have an EditText
where user can type in something. After user finishes typing (they press next, etc.), I want to perform a check on what they typed in.
String userInput = String.valueOf(editText.getText()).trim();
Let's say userInput
value is appla
. That means what user typed in is only one letter off the world Apple
(which is in the array).
That's the check I want to implement. Whatever the user types in, if one SIMILAR (1 or 2 letters off) word exists in the array, I want to get that word. How would I go about implementing that?
Result examples:
aoole ==> Apple
orenge ==> Orange
Cheery ==> Cherry
I was able to figure this out. It doesn't go exactly the way I wanted (1 or 2 letters off) but it does the job because it gives the of percentage of similarity.
I used this library.