0

I'm developing an app in Android in Kotlin, and in one activity I have 10 editText. How i could get the text of all editTexts within a for loop? EditTexts are into Constraint Layouts, which are into a Linear Layout.enter image description here

1 Answer 1

2

You can iterate over the child views of the parent view group and just gather the texts, something like this:

val parentView: ViewGroup = findViewById(R.id.parent)
for (i in 0 until parentView.childCount) {
    val view: View = parentView.getChildAt(i)
    if (view is EditText) {
        Log.d("text", view.text.toString())
    }
}

Change the R.id.parent to the correct id of course - the id of your constraint layout.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.