From ba478cde2b1198b073a8a32bb66f860c64dc10dc Mon Sep 17 00:00:00 2001
From: lizhanwei <Dana_Lee1016@126.com>
Date: 星期三, 22 四月 2020 16:53:13 +0800
Subject: [PATCH] 完成查看车载信号输入

---
 app/src/main/java/safeluck/drive/evaluation/customview/MyCustomEditText.kt |   60 ++++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/app/src/main/java/safeluck/drive/evaluation/customview/MyCustomEditText.kt b/app/src/main/java/safeluck/drive/evaluation/customview/MyCustomEditText.kt
index e9f6721..bbe0e23 100644
--- a/app/src/main/java/safeluck/drive/evaluation/customview/MyCustomEditText.kt
+++ b/app/src/main/java/safeluck/drive/evaluation/customview/MyCustomEditText.kt
@@ -1,11 +1,9 @@
 package safeluck.drive.evaluation.customview
 
 import android.content.Context
-import android.content.res.TypedArray
-import android.os.Parcel
-import android.os.Parcelable
 import android.text.Editable
 import android.util.AttributeSet
+import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
 import android.widget.EditText
@@ -29,10 +27,17 @@
 
 class MyCustomEditText : LinearLayout{
 
-    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context,attrs,defStyleAttr,defStyleRes) {
-        mcontext = context
-        init()
+    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
@@ -40,38 +45,57 @@
     var str:String=""
     var desstr:String=""
 
-    var mcontext:Context?= null
     var txtDes:TextView? = null
     var txtDesUnit:TextView? = null
     var et_num:EditText? = null
     var view: View? = null
-    override fun onFinishInflate() {
-        super.onFinishInflate()
+
+
+    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
+            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 init(){
-        view = LayoutInflater.from(mcontext).inflate(R.layout.layout_mycustom_et,null)
-
-        var attributeSet = mcontext?.obtainStyledAttributes(R.styleable.mycustom_et)
-        //鑾峰彇鏄惁瑕佹樉绀哄崟浣�
-        visiblity = attributeSet?.getBoolean(R.styleable.mycustom_et_txt_unit,true)!!
-        str = attributeSet?.getString(R.styleable.mycustom_et_txt)
-        desstr = attributeSet?.getString(R.styleable.mycustom_et_txt_des)
 
 
+    fun updateStr(str:String){
+        et_num?.text = Editable.Factory.getInstance().newEditable(str)
+        invalidate()
     }
 
 }

--
Gitblit v1.8.0