uesports135
uesports135

Reputation: 1123

Android adding multiple views to viewgroup

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

Answers (1)

Numan1617
Numan1617

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

Related Questions