Java 如何替换android的EditText中最后输入的字符串?

Java 如何替换android的EditText中最后输入的字符串?,java,android,arrays,string,android-edittext,Java,Android,Arrays,String,Android Edittext,我从sqlite数据库中获取了两个字符数组。一个数组由普通字体字符组成,另一个数组由样式字体字符组成 问题是,当我选择普通字体字符数组并替换在EditText中输入的字符时。它工作正常,但在EditText中键入特定字符后,在EditText中使用另一个字体字符数组。然后替换EditText中输入的旧字符 watcher = new TextWatcher() { @Override public void afterTextChanged(Editable s) { } @Overrid

我从sqlite数据库中获取了两个字符数组。一个数组由普通字体字符组成,另一个数组由样式字体字符组成

问题是,当我选择普通字体字符数组并替换在
EditText
中输入的字符时。它工作正常,但在
EditText
中键入特定字符后,在
EditText
中使用另一个字体字符数组。然后替换
EditText
中输入的旧字符

watcher = new TextWatcher() {

@Override
public void afterTextChanged(Editable s) {

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {

}

@Override
public void onTextChanged(CharSequence ss, int start, int before,
int count) {
    edt.removeTextChangedListener(watcher);

    String str = edt.getText().toString();

    String a = styleArray.get(0);
    String b = styleArray.get(1);
    String c = styleArray.get(2);

    str = str.replaceAll("a", a);
    str = str.replaceAll("b", b);
    str = str.replaceAll("c", c);

    edt.setText(str);
    edt.addTextChangedListener(watcher);
    int position = edt.getText().length();

    Editable ed = edt.getText();

    Selection.setSelection(ed, position);
}
};
这是我用来替换
EditText
中字符的代码

watcher = new TextWatcher() {

@Override
public void afterTextChanged(Editable s) {

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {

}

@Override
public void onTextChanged(CharSequence ss, int start, int before,
int count) {
    edt.removeTextChangedListener(watcher);

    String str = edt.getText().toString();

    String a = styleArray.get(0);
    String b = styleArray.get(1);
    String c = styleArray.get(2);

    str = str.replaceAll("a", a);
    str = str.replaceAll("b", b);
    str = str.replaceAll("c", c);

    edt.setText(str);
    edt.addTextChangedListener(watcher);
    int position = edt.getText().length();

    Editable ed = edt.getText();

    Selection.setSelection(ed, position);
}
};
从数据库中获取的两个数组是:

a. {a,b,c}
b. {ⓐ, ⓑ, ⓒ}

示例:当我选择第一个数组{a,b,c}时,假设在
EditText
框中输入的文本是“abc”。从这里就可以了。但当我选择另一个字体字符数组时{ⓐ, ⓑ, ⓒ} 并在edittext中输入文本,则结果必须为“abc”ⓐⓑⓒ". 而不是这个结果“abc”ⓐⓑⓒ“我要走了”ⓐⓑⓒⓐⓑⓒ“。它还替换了旧输入的字符。那么,这背后的逻辑是什么呢?我尝试了很多,但没有找到解决方案。

@pareshmayani帮助我……EditText似乎只允许使用一种字体,相当于
android:fontFamily
。因此,我想,当您将文本与其他字体粘贴在其中时,它会被覆盖。”。