In my program there are a large number of consecutive text elements. It looks like this:

item1

item2

item3

item4

...

And there is a goal to filter out these elements in order to get only those that satisfy the applied filtering at the output:

item3

item4

...

To implement this plan, I have two ways:

1) create a Layout, where each element will be in the form of a TextView:

<TextView android:id="@+id/item1" android:text="@string/item1" /> <TextView android:id="@+id/item2" android:text="@string/item2" /> <TextView android:id="@+id/item3" android:text="@string/item3" /> <TextView android:id="@+id/item4" android:text="@string/item4" /> 

Then in the code simply hide those that do not satisfy the filtering:

 if(blahblah)item1.setVisibility(View.GONE); if(blahblahblah)item2.setVisibility(View.GONE); 

2) create a ListView and update its adapter after each filtering:

 if(blahblah)items[0]=""; if(blahblahblah)items[1]=""; List<String> finalList = new ArrayList<>(Arrays.asList(items)); finalList.removeAll(Arrays.asList("", null)); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, finalList); listView.setAdapter(adapter); 

I decided that hiding the View-element requires less performance than updating the whole adapter, so I started writing Layouts. That's just the amount of TextView is really large, no joke, exactly 666 pieces (I did not try, it happened). Could this fact have an even more negative impact on performance?

    1 answer 1

    ListView more productive solution for this task, as it is optimized for outputting a large amount of data by reusing items.
    In fact, only the number of View objects needed to be displayed on the screen is 5-10 pieces and they are interchanged for a list of any length, while in the version with Layout will be as many View objects as there are items in your list, which is very sad for the memory .

    In addition, ListView has already implemented tools for working with items, in the variant with Layout you will have to implement everything yourself and it’s not a fact that you can do better than the developers of the platform.