Edittext 的常量后缀,即使在添加字符后也会存在

Constant Suffix to Edittext that will be there even after adding characters

我想要这样的东西。

输入数字后'X10^3C'应该保持不变

使用文本观察器实现此目的

    //global variable
        Boolean isAvaialable = false; 

    // text watcher
        txtAdvertise.addTextChangedListener( new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                    }

                    @Override
                    public void afterTextChanged(Editable s) {


                          if(!txtAdvertise.getText().toString().contains("X10^3c") && !isAvaialable) {
                              txtAdvertise.setText(txtAdvertise.getText() + "X10^3c");
                              isAvaialable = true;
                            }
                         else if(txtAdvertise.getText().length() == 0 && isAvaialable && !txtAdvertise.getText().toString().contains("X10^3c")){
                              txtAdvertise.setText(txtAdvertise.getText() + "X10^3c");
                              isAvaialable = false;
                        }
  }
        });