如何在 Java 中创建一个自动更正功能,让我可以在用户输入时替换他们输入的内容?

How can I Create an Autocorrect in Java that Will Let Me Replace User Input as They Type?

我正在尝试在 android 应用程序中实时更改用户输入(我正在使用 android studio)。当用户输入时出现拼写错误,我想创建自己的自动更正功能,自动为他们更正错误。

例如,用户打算输入 "Meeting with Rob.",不小心输入了 "Meetng"

无需用户点击建议或任何其他内容,"Meetng" 变为 "Meeting",就像 phone 上的常规自动更正功能一样。

注:

在这种情况下,代码效率无关紧要,我不想使用常规的内置自动更正,因为这部分代码是其他内容的一部分,需要我完全控制发生的自动更正。我不认为我可以使用常规的自动更正,但如果我错了请纠正我。

代码:

void checkWordAndAutocorrectIt(){

            if (dict.contains(VEvent.DESCRIPTION) || newDictionary.contains(VEvent.DESCRIPTION)) {
                //then you don't need to do anything I don't think but
                //this is here in case it starts ignoring words that haven't been autocorrected
                //so I can append them manually onto the string
            } else if (!dict.contains(VEvent.DESCRIPTION) && !newDictionary.contains(VEvent.DESCRIPTION)) {
                VEvent.DESCRIPTION.replace(VEvent.DESCRIPTION, autoCorrector(VEvent.DESCRIPTION));
                //this should hopefully replace the incorrect word with the corrected one returned by autoCorrector
                for (int i = 1; i <= 3; i++) {
                    if (val.get(i).autoCorrection == "") {
                        val.get(i).autoCorrection = autoCorrector(VEvent.DESCRIPTION);
                    } //this should check if there is a word already in the spot
                    //if not, it should save the autocorrected word.
                }
            }
        }

感谢您提供的任何帮助、建议或资源!

因此,根据此 (How to convert input char to uppercase automatically in Java),显然在 java 中无法更改用户输入,这正是我所担心的。猜猜我要改变我的项目。