lugiank
lugiank

Reputation: 81

Populating very long linear layout with custom views, extremely slow

i'm trying to populate a linear layout with a list of custom views like in the picture:

Layout scheme To achieve this i'm inflating the foo.xml in a new View object, then i change the textviews using .setText and then i add the new View to the linear layout.

The problem is: it is extremely slow, even outside the emulator, taking more than 10 seconds to display in my S9.

LinearLayout layout = findViewById(R.id.layout);

while(a<500){
    Person person = new Person();

    View personData = inflater.inflate(R.layout.person, layout, false);
    layout.addView(personData);
    ((TextView) coinData.findViewById(R.id.textView_text_name)).setText(person.name);

    a=a+1
}

EDIT: Thank you guys! I'm gonna try RecyclerView right now

Upvotes: 1

Views: 371

Answers (1)

Chirag Sharma
Chirag Sharma

Reputation: 888

For creating a list use RecyclerView which is just advanced version of traditional ListView

You can Follow tutorial for Recycler View Here.

Upvotes: 1

Related Questions