1

I have to add multiple view programatically to a HorizontalScrollView but i can not add the same inflated view twice. So i have to re-inflate my XML layout N times. An adapter solution is not an option.

There is a way to recycle this layout without re-inflating?

Thanks to all.

UPDATE: My code is something like this.

View view = getLayoutInflater().inflate(R.layout.my_view, null);
HorizontalScrollView h = (HorizontalScrollView)findViewById(R.id.scroll);

for(int i = 0; i < 25; i++)
{
  // Process textview and images inside the view
  h.addView(view);
}
Ollie Strevel
  • 861
  • 1
  • 14
  • 27

1 Answers1

0

I am not sure this what you are looking for we can inflate layout like this

LayoutInflater.from(context).inflate(R.layout.abc_action_bar_decor, parent, true);
HorizontalScrollView h = (HorizontalScrollView)findViewById(R.id.scroll);
LinearLayout parent= new LinearLayout(context);
parent.setOrientation(LinearLayout.HORIZONTAL);
h.addView(parent);
for(int i = 0; i < 25; i++)
{
   View view = getLayoutInflater().inflate(R.layout.my_view, parent, true);
   // Process textview and images inside the view
}
Kamalanathan
  • 1,747
  • 3
  • 22
  • 33
  • This is what i want avoid: use the inflate function n times, i want to inflate my layout once and re use it in the for loop – Ollie Strevel May 04 '14 at 15:59
  • @OllieStrevel This won't work, for each displayable list item you need a different View object, thus you need to inflate your layout for each item. – DrNachtschatten Sep 28 '17 at 09:09