1

I have looked at this topic to dynamically add views when needed: Add and Remove Views in Android Dynamically?

However, I have a few questions.

1) Will there be a visible stutter or lag when creating these views on the go? For example, I use a panel system where each panel holds a separate view. However, these panels could reach a high number in quantity (40 odd panels?) when the program is complete. In order to preserve resources, I want only the view that is currently visible to actually be created, and the others views to not be instantiated until they are brought into the visible region. I have been told to use a ViewFlipper, but due to animation and user interaction requirements of my program, I cannot use a ViewFlipper, but have something along the same lines that I have created.

For example:

Imagine one of my "panels" to be pretty much like a screen in the Android Home launcher. The thing with the Home Launcher is that all it's views can be kept alive at any given time, because there's only really 7 of them. However, seeing as there are closer to 40 in mine (not all left and right, some above and below as well), I cannot have them all instantiated at the same time, or else the phone will begin to lag.

2) What is the code to destroy the views once they aren't in the visible region?

My program will determine when the panels are in the visible region or not, hence I will only need the code to destroy the views on the go.

Thanks.

Community
  • 1
  • 1
Allister Smith
  • 204
  • 3
  • 7

1 Answers1

0

Why don't you use a ListView or a GridView?

If you are not willing to use some of those, you will need to do something similar to what they do with the Adapter and how they recicle views.

Macarse
  • 91,829
  • 44
  • 175
  • 230
  • How can I use a ListView or GridView in the way that I need it to be, as described above? A single "panel" occupies the entire screen. Other Views are added to this panel, but irrespective of what is on the panel, a single panel can be considered to be a View of it's own. – Allister Smith Jan 23 '11 at 13:36
  • Sorry, forgot to also mention - I have been told about how the Adapter class recycles views, but I haven't been successful in linking it to how it should be used in my program. Do you have any pointers or starting tips for me to use in order to apply the Adapter theory in my program? – Allister Smith Jan 23 '11 at 13:37
  • Can you provide an screenshot of how it should look? – Macarse Jan 24 '11 at 00:43
  • Let me see what I can do quickly. I shall whip up something in PS. – Allister Smith Jan 24 '11 at 06:25
  • Ok, here's the link to an attempt at explaining my system: http://tinypic.com/r/6f0277/7 – Allister Smith Jan 24 '11 at 06:56
  • What you will see is that individual panels are grouped together into "panel systems". Each individual panel will occupy the full screen space. Moving between panels in a "panel system" is done with swipe gestures, but to move to new a new "panel system", the user will perform other actions, like clicking buttons or other objects. This will open up a new "panel system". My problem is that I might, for example, need to access Panel8 from Panel1 at any given time. This leads me to believe that Activities might be better to use, because I can launch the required activity whenever I need it. – Allister Smith Jan 24 '11 at 06:59
  • @MrPadie: Check Android's Gallery: http://developer.android.com/reference/android/widget/Gallery.html Here's an example: http://developer.android.com/guide/tutorials/views/hello-gallery.html – Macarse Jan 24 '11 at 11:22