yy1717
2021-02-02 c3e207bd4a37f4f4cafbf43b897592ac3c582e45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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 MyCustomEditText : 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,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()
    }
 
}