0

I'm new to Android Development and I'm having a problem cloning a View multiple times.

That's my code:

    RelativeLayout billboard = (RelativeLayout)findViewById(R.id.billboard);

    int x;
    x = 1;
    while (x <= 100) {
        LinearLayout billboardEntry = (LinearLayout)findViewById(R.id.billboardEntry);

        View billboardEntryView = getLayoutInflater().inflate(R.layout.billboardentry, billboard, false);
        billboard.addView(billboardEntryView);

        x++;                     
    }   

This code appends the LinearLayout only one time. Any ideas?

Thanks!

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • I think you should look into ListView http://developer.android.com/guide/topics/ui/layout/listview.html – andrei Jun 19 '14 at 10:00
  • 1
    It is meant to be used in cases like yours. If you are going to use a ListView then you should also read about the ViewHolder pattern and about using the convertView, it will greatly improve performances – andrei Jun 19 '14 at 10:07
  • I've tried adding it to the ListView, but the App crashes with "The specified children already has a parent." – Mathis Schülingkamp Jun 19 '14 at 10:09
  • Probably it is adding one over the other – HJK Jun 19 '14 at 10:17
  • First of all, after looking at the ListView, is it something like this that your are looking to implement? If so, you can't just add a view to the listView, you'll have to create an adapter and pass it a list of objects. you have an example in the link – andrei Jun 19 '14 at 10:28
  • I'm not sure. I need something like Posts, with Head, Content and Buttons, I don't know if ListView is the right thing there.. Otherwise, what should I use? And how can i prevent adding one over the other? – Mathis Schülingkamp Jun 19 '14 at 10:32

0 Answers0