package safeluck.drive.evaluation.customview
|
|
import android.content.Context
|
import android.text.Editable
|
import android.util.AttributeSet
|
import android.util.Log
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.widget.EditText
|
import android.widget.LinearLayout
|
import android.widget.TextView
|
import safeluck.drive.evaluation.R
|
|
/**
|
*
|
* @ProjectName: DriveJudge
|
* @Package: safeluck.drive.evaluation.customview
|
* @ClassName: MyCustomEditText
|
* @Description: java类作用描述
|
* @Author: 李占伟
|
* @CreateDate: 2020-04-22 14:05
|
* @UpdateUser: 更新者
|
* @UpdateDate: 2020-04-22 14:05
|
* @UpdateRemark: 更新说明
|
* @Version: 1.0
|
*/
|
|
class MyArgEditText : LinearLayout{
|
|
private val TAG= "MyCustomEditText"
|
|
constructor(context: Context) : this(context, null)
|
constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
|
|
constructor(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int):super(context,attributeSet,defStyleAttr){
|
init(context,attributeSet)
|
}
|
|
|
|
|
// true就是显示 false不显示
|
var visiblity:Boolean = true
|
|
var str:String=""
|
var desstr:String=""
|
|
var txtDes:TextView? = null
|
var txtDesUnit:TextView? = null
|
var et_num:EditText? = null
|
var view: View? = null
|
|
|
fun init(context: Context, attributeSet: AttributeSet?){
|
Log.i(TAG,"myCustomEditText z自定义---------")
|
view = LayoutInflater.from(context).inflate(R.layout.layout_mycustom_et_arg,this,true)
|
|
txtDes = view?.findViewById(R.id.tv_des_et)
|
txtDesUnit = view?.findViewById(R.id.tv_unit)
|
et_num = view?.findViewById(R.id.et_num)
|
|
var a = context.obtainStyledAttributes(attributeSet,R.styleable.mycustom_et)
|
//获取是否要显示单位
|
visiblity = a!!.getBoolean(R.styleable.mycustom_et_txt_unit,true)
|
str = a!!.getString(R.styleable.mycustom_et_txt)
|
desstr = a!!.getString(R.styleable.mycustom_et_txt_des)
|
|
var desunit = a!!.getString(R.styleable.mycustom_et_txt_unit_des)
|
// var width = a!!.getString(R.styleable.mycustom_et_view_width)
|
// var height = a!!.getString(R.styleable.mycustom_et_view_height)
|
|
Log.i(TAG,"txtDes=$desstr")
|
Log.i(TAG,"str=$str")
|
Log.i(TAG,"visiblity=$visiblity")
|
|
|
|
when(visiblity){
|
true->{
|
txtDesUnit?.visibility = View.VISIBLE
|
txtDesUnit?.text = desunit
|
}
|
else-> txtDesUnit?.visibility = View.GONE
|
}
|
|
txtDes?.text = desstr
|
et_num?.text = Editable.Factory.getInstance().newEditable(str)
|
|
a.recycle()
|
|
|
}
|
|
|
|
fun updateStr(str:String){
|
et_num?.text = Editable.Factory.getInstance().newEditable(str)
|
invalidate()
|
}
|
|
}
|