我想要这样的东西。
即使输入数字后,'X10 ^ 3C也应保持不变。
答案 0 :(得分:1)
使用文本观察器来实现此目的
//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;
}
}
});