Reputation: 1123
I have a simple question. I have an arrayList of views I want to add to a ViewGroup. I currently am iterating through them with a for loop and adding them individually.
ViewGroup commentList = (ViewGroup) this.findViewById(R.id.comment_list);
for (View commment: comments) {
commentList.addView(commment);
}
Can I do this all at once with a single call? Like an addAll() method? I feel like this would be more efficient, especially if I have a lot of views I'm adding....
Upvotes: 2
Views: 1226
Reputation: 1178
Iterating through the views if there are a lot is fairly efficient. If this ViewGroup is going to always have a lot of views you may want to consider using a view type that uses an adapter and recycling / reuse otherwise you'll have a lot of views that are in memory yet are off screen.
Upvotes: 1