大家在开发过过程中可能会遇到 这样的需求 就是 只是需要保留 小数点后几位如图 在这里因为项目的 需要我这边 需要做一个整数位数只能输入十位 小数位数只能输入两位
这样的需求 虽然大家可以实现 但是 为这样一个简单的需求 耗费时间感觉跟不值得 在这里 小编 使用的是一个封装好了的 Edtext方便大家使用
这个是封装好的一个Edtext 在这里边最主要是添加了一个过滤器
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.sinoservices.wmsrf.R;
/**
* Created by Francis on 2017/12/20.
* 保留指定位数的小数点
*/
public class OKeepDecimalEditText extends AppCompatEditText {
public boolean isInput = false;//是否是输入的
ICallBack icallBack = null;
public OKeepDecimalEditText(@NonNull Context context) {
super(context,null);
}
public OKeepDecimalEditText(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.KeepDecimalEditText, 0, 0);
typedArray.getIndexCount();
typedArray.getIndex(0);
int befor_integer = typedArray