activity中的:
/**
* 默认融资金额
*/
private long defaultMoney = 1_0000;
/**
* 点击减少10000意向融资金额
*/
@OnClick(R.id.ib_finance_intention_delete)
void clickDelMoney(){
if(defaultMoney> CheckUtil.MIN_MONEY){
defaultMoney -= 10000;
mAmountView.setText(String.valueOf(defaultMoney));
mAmountView.setSelection(mAmountView.getText().length());
}
}
/**
* 点击增加10000意向融资金额
*/
@OnClick(R.id.ib_finance_intention_add)
void clickAddMoney(){
if(defaultMoney<CheckUtil.MAX_MONEY){
defaultMoney+=10000;
mAmountView.setText(String.valueOf(defaultMoney));
mAmountView.setSelection(mAmountView.getText().length());
}
}
//et_finance_intention_amount_money 文本卡的id
@OnTextChanged(R.id.et_finance_intention_amount_money)
void changeIntentMoney(CharSequence charSequence){
mAmountView.setSelection(mAmountView.getText().length());
if(!TextUtils.isDigitsOnly(charSequence)){
ToastUtil.showFailure(this,"错误的金额");
return;
}
defaultMoney=CheckUtil.converIntentMoney(charSequence.toString());
}
CheckUtil:帮助类
/**
* 最小意向融资金额
*/
public static final int MIN_MONEY = 5_000;
/**
* 最大意向融资金额
*/
public static final int MAX_MONEY = 3_000_000;
/**
* 转换为合法意向融资金额
*
* @param inputMoney 输入金额
* @return 转换后金额
*/
public static long convertIntentMoney(CharSequence inputMoney) {
if (TextUtils.isEmpty(inputMoney) || inputMoney.length() < 4 || !TextUtils
.isDigitsOnly(inputMoney)) {
return MIN_MONEY;
} else if (inputMoney.length() > 9) {
return MAX_MONEY;
} else {
long intMoney = Integer.parseInt(inputMoney.toString());
if (intMoney < MIN_MONEY) {
return MIN_MONEY;
} else if (intMoney > MAX_MONEY) {
return MAX_MONEY;
} else {
return intMoney - intMoney % 1000;
}
}
}