Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virendersran01/25c0065c067f28f8a05a9254a949a7b0 to your computer and use it in GitHub Desktop.
Save virendersran01/25c0065c067f28f8a05a9254a949a7b0 to your computer and use it in GitHub Desktop.
Function to create input fields inside flexbox dynamically.
private val mTextMap: HashMap<Int, TextMapModel> = HashMap()
private val mTextIdArray: ArrayList<Int> = ArrayList()
private fun createInputFieldsInInputBox(actualText: String) {
val textLength = actualText.length
val flexboxLayout = mBinding.flexboxLayoutInput
flexboxLayout.flexDirection = FlexDirection.ROW
val filterArray = arrayOfNulls<InputFilter>(1)
filterArray[0] = InputFilter.LengthFilter(1)
for (i in actualText.indices) {
val editText = EditText(requireContext())
editText.id = generateRandomIntForViews() // a method in utils
editText.setTextColor(
ContextCompat.getColor(
requireContext(),
R.color.white
)
)
val colorStateList = ColorStateList.valueOf(
ContextCompat.getColor(
requireContext(),
R.color.white
)
)
editText.backgroundTintList = colorStateList
editText.inputType = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
editText.filters = filterArray
val lp = FlexboxLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT
)
editText.layoutParams = lp
setTextWatcher(editText)
mTextMap[editText.id] = TextMapModel(" ", editText)
mTextIdArray.add(i, editText.id)
flexboxLayout.addView(editText)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment