How can I dynamically add item to a Gallery in android

by ying lcs » Thu, 05 Mar 2009 09:03:11 GMT

Sponsored Links

Can you please tell me how can I dynamically add item to Gallery?
I have looked at ApiDemo and have studied their example.

But the ImageAdapter there is a BaseAdapter which has a fixed sized
array and the getCount() just return the length of the array.
My question is how can I change that to a dynamically size vector? I
have set breakpoints in getCount(), and it only called once
dynamically during initialization.  So how can I tell android that the
gallery size has changed?

Thank you.


Other Threads

1. my app sometimes take <1 second to load, sometimes 50 seconds

Hi all,

I'm pretty stumped here.

I've got an app that more or less follows the layout of LunarLander,
with an Activity, a View, and a Thread. The View extends SurfaceView
and the thread is what does the drawing. It is relatively light on
resources - 16 PNGs totalling 240KB, one simple layout xml, and one
simple values xml.

The load time for the app is all over the map. It sometimes loads in
under a second, sometimes it takes as much as 50 seconds. But as long
as I don't touch it, it *always* finishes loading eventually (if I try
to interact with it, I get the "isn't responding" window and have the
option to kill it.. though even then it will finish loading if I wait
long enough). The behavior is the same whether I'm running my code on
the emulator or an actual ADP1.

I've done a fair amount of logging to try to figure out what's going
on, but I'm not getting anywhere. My activity's onStart() is always
done in less than 2 seconds; my view and thread are also ready to go
within 2 seconds. Even my first call to onDraw() is always done in
under 3 seconds from the time the activity starts.

After all that is done, I'll be starting at a blank screen (with my
title bar) for a very arbitrary amount of time. Finally, the logcat
will show me:

I/ActivityManager( 52): Displayed activity 11301 ms
Of course, 11301 ms is sometimes 800ms, 3000ms, 20000ms, or 50000ms
instead. Unfortunately, until that line shows up, my app is
unresponsive and does not actually fill in the black space on the

I can't figure out what is going on in the time between when my app
seems to be saying it's completely ready and when android decides it's
ready to go. Has anyone else seen this? Does anyone else have any

2. Text animation question


I'm working on some text animation with 2 left and right buttons,
iterating through an array, and scrolling the text off of the screen
(so left button scrolls the text off the screen to the left, and vice-

The problem I'm finding, is that I want to keep the current text until
the animation has been completed, and _then_ change the text (next
item in the array), but the text seems to change first, and then

Here's my XML for animation (R.anim.anim_left):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android=""
android:shareInterpolator="true" android:interpolator="@android:anim/

    <translate android:fromXDelta="0"

And the code for the button:
if (v == btnLeft) {
TextView animWindow = (TextView)findViewById(;
Animation anim = AnimationUtils.loadAnimation(Main.this,

final ArrayAdapter<String> namesArray = new ArrayAdapter<String>
(Main.this, R.array.myArray, getResources().getStringArray
Names -= 1;

Has anyone else experienced something similar to this, or have any

Thanks much in advance!

3. Connecting a Google Dev phone to UK Vodafone

4. Tracking data/hiding things in a list

5. Map Example throwing class not found exception

6. Imageview and ArrayAdapter

7. Lock phone to control access