1.首先给用户添加一个textchangedlistener
2.然后再写一个文字变化的监视器
代码如下:
mobile_et.addTextChangedListener(textWatcher);
TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
if(s.length() == 11){
String amountYuan = amount_et.getText().toString();//用户选择的金额+元
String mobileNum = mobile_et.getText().toString().trim();
int tMobile = Utils.getMobileOp(mobileNum);
String disAmount= getDisAmount(tMobile, amountYuan);
amount_discount_tv.setText(disAmount);
}
}
};