Reputation: 128
Is it possible to somehow take an array, for example, a TextView, which are in the current Activity, or is it necessary to take each view?
Upvotes: 0
Views: 32
Reputation: 67
You can get all the views of your xml programmatically as below:
bind your ViewGroup / Parent layout
Then the child View are accessible in if condition
val container = findViewById(R.id.container) as ViewGroup
for (i in 0 until container.childCount) {
val v = container.getChildAt(i)
if (v is Button) {
// You will get Button here
}
else if(v is TextView){
// You will get textView here
}
}
Upvotes: 1