如何使用编辑文本和unicode?

时间:2016-07-27 18:20:14

标签: java android xml unicode replace

当运行活动停止时,这是我的活动。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final EditText et = (EditText) findViewById(R.id.et);
    final TextView tv = (TextView) findViewById(R.id.textView8);
    final String a = "a";
    final String b = "b";
    final String c = "c";
    final String d = "d";
    final String e = "e";
    final String f = "f";
    final String g = "g";
    final String h = "h";
    final String a1 = "\u24B6";
    final String b1 = "\u24B7";
    final String c1 = "\u24B7";
    final String d1 = "\u24B9";
    final String e1 = "\u24BB";
    final String f1 = "\u24BB";
    final String g1 = "\u24BD";
    final String h1 = "\u24BD";
    et.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
        }

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            String name = et.getText().toString();
            name = name.replaceAll(a,a1);
            name = name.replaceAll(b, b1);
            name = name.replaceAll(c, c1);
            name = name.replaceAll(d, d1);
            name = name.replaceAll(e, e1);
            name = name.replaceAll(f, f1);
            name = name.replaceAll(g, g1);
            name = name.replaceAll(h,h1);
            tv.setText(name.trim());

        @Override
        public void afterTextChanged(final Editable s) {
        }
    });
}
}

解决方案是什么?

请写出正确的代码,因为堆栈溢出中的所有代码都是错误的。

请帮我解决这个问题,因为这很难。

1 个答案:

答案 0 :(得分:0)

您可以使用URLEncoder

String encodedURL = URLEncoder.encode(yourInputString, "UTF-8");

然后根据需要使用URLDecoder解码,无论您在何处使用它。