If TextViews
is the main part of these layouts, I don’t think there will be a big difference in performance so you can go anyway. I will go with option two because:
The ratio between the number of lines of regular lines and special lines is great. If you adhere to a unified approach to placement, you will have to change the layouts in the code for each line, regular or special, because you can deal with a redesigned View
that has 2/3 of the parts hidden when it is time to show normal (so you're in end up changing the layout every time). If you used the second option, you could eliminate this part from the getView
method and just use switch
to see what type of row you are dealing with (without additionally modifying the layout of the row every time in getView
, you will enable the ListView
descriptor by providing you with the correct line layout type). Do not worry about bloating another layout file (once), this does not affect performance.
Using one type of layout means that you have Views
left in memory even if the user does not see them (so you can prevent the ListView
inflating more Views
(only once, actually), but at the same time you take up more memory with those that you don’t even show to the user). The first option has the advantage that the data binding to the string is simpler, since you have all the views at your disposal (even if the user does not see part of them) instead of the second option, where you would see what data should be displayed based on the type strings.
Reading code. Having two types of lines and testing to find out which one you are using in the getView
method, it is more getView
, because you see what logic you have for each type of line. It will also be better if you plan to change these line layouts in the future or add more line types.
ListView
does a great job of viewing views if you help it provide row types. Edit: ListView
save a redesigned view for each type declared in the adapter. Thus, the ListView
will inflate the second layout only the first time it finds it in the ListView
, the next time it needs a string with a type, it will use the recycled one (and will support 2 types of recycled views, the type of the first and second row) .
source share