Last active
August 27, 2019 11:14
-
-
Save lukelorusso/41051c7c4c5a30454e1b5eb8ea9b809b to your computer and use it in GitHub Desktop.
onAttachedToWindow()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var text: Editable = "".toEditable() | |
set(value) { | |
field = value | |
renderCode() // let's keep this for later | |
} | |
... | |
override fun onAttachedToWindow() { | |
super.onAttachedToWindow() | |
... | |
if (!isInEditMode) { | |
llCodeWrapper.removeAllViews() | |
for (i in 0 until maxLength) { | |
View.inflate( | |
context, | |
R.layout.item_code_edit_text, | |
findViewById(R.id.llCodeWrapper) | |
) | |
} | |
if (text.isNotEmpty()) editCodeReal.text = text | |
editCodeReal.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(maxLength)) | |
editCodeReal.removeTextChangedListener(textChangedListener) | |
editCodeReal.addTextChangedListener(textChangedListener) | |
llCodeWrapper.setOnClickListener { | |
editCodeReal.apply { | |
showKeyboard() | |
focusOnLastLetter() | |
} | |
} | |
} | |
... | |
} | |
private val textChangedListener = object : TextWatcher { | |
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} | |
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {} | |
override fun afterTextChanged(s: Editable) { | |
text = s | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment