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);
}
}
};