catchphrase.addTextChangedListener(object:TextWatcher{
override fun afterTextChanged(s: Editable?) {
if(s?.length?:0>20){
KoolearnApp.toast(R.string.share_edit_number_over100)
catchphrase.setText(catchphrase.text.toString().substring(0,20))
catchphrase.setSelection(catchphrase.text.toString().length)
}
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
})
複製代碼
設置輸入類型爲數字bash
extendEdit.inputType = EditorInfo.TYPE_CLASS_NUMBER
複製代碼
限制輸入字數ide
extendEdit.setFilters(arrayOf(InputFilter.LengthFilter(length)))
複製代碼