1

I am comfortable with creating the gallery in the xml and then using it in the java file. However, I am trying to create a new gallery view in the java file. Reasoning is I am not sure at launch how many gallery views I would need and would like to be able to dynamically create gallery view as needed.

TIA

Andrew
  • 830
  • 3
  • 10
  • 27

1 Answers1

1

You can use a LayoutInflater to get a view from your xml and create as many new instances of it as you want based on whatever your business logic is. I'm not sure I understand when/why it would make sense to do this though...

To use a LayoutInflater, do something like this:

View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.somelayout,
                null);

Then you can do whatever you want with it.

LuxuryMode
  • 33,401
  • 34
  • 117
  • 188
  • I have some images in separate albums online, i want to show these in gallery views (one for each album) and I do not always know the number of albums. After I inflate the layout, how do I add a gallery view to it? – Andrew Nov 14 '11 at 18:13
  • Why do you need separate gallery views? What exactly do you expect the final layout to look like...? – LuxuryMode Nov 14 '11 at 18:15
  • multiple gallery views, each for a separate album.. vertically stacked on top of each other.. – Andrew Nov 14 '11 at 18:17