Android Kotlin TextView EditText 扩展函数
/**
* Kotlin TextView 扩展函数判空
*/
private fun TextView?.checkNotEmpty():Boolean{
if(this == null){
return false
}
if(!this.text.toString().isNullOrEmpty()){
return true
}
return false
}
/**
* Kotlin EditText 扩展函数判空
*/
private fun EditText?.checkNotEmpty():Boolean{
if(this == null){
return false
}
if(!this.text.toString().isNullOrEmpty()){
return true
}
return false
}
/**
* Kotlin EditText 扩展函数增加监听器
*/
private fun EditText?.addListener(){
if(this == null){
return
}
this.addTextChangedListener(object :TextWatcher{
override fun afterTextChanged(s: Editable?) {
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
})
}
/**
* 根据文件路径删除文件
*/
private fun String.delete() {
if (this == null || this.isEmpty()) {
return
}
val file = File(this)
if (file != null && file.exists()) {
file.delete()
}
}