0

So i have a listview that i want to populate with headers and a view layout with some images and some text.

What is the most performance efficient way to go about this?

Inflate a layout for the header and another for the normal view or use the same layout for both only with some formatting and re-formatting to achieve the goal?

Cheers

1 Answers1

0

If each row will be the same layout format, then it would be better to have one layout that you inflate in your getView() method within the ListView adapter. When this View is inflated, you can than access the TextViews and ImageViews within the layout and configure them to how you would like. I believe that inflating only one view would provide for a quicker and more memory-effecient method.

krodmannix
  • 845
  • 10
  • 30
  • Well to be honest the layout has 3 textviews and one imageview. For the header i'm making 2 of the textviews and the imageview disappear and changing the background color and the other textview color and padding. i then change it all back. –  May 27 '14 at 13:34
  • So, you can use `your_text_view.setVisibility(View.INVISIBLE)`, `your_inflated_view..setBackgroundColor(0xFF00FF00);`, etc. All those values can be changed programmatically. I would put some sort of flag in your adapter to notify that a view is either a header or a regular row, and check for this flag in your `getView()` method. – krodmannix May 27 '14 at 13:42
  • Yeah, i got that all covered to be honest, i just was unsure if i should be inflating a new layout for the header to optimize performance. –  May 27 '14 at 13:43