Sorry, your question slipped under my radar, but here goes the (late)
answer.
First, let me explain what I wanted to achieve. The list I was going
to present in the dialog could potentially contain a lot of images, so
loading them all and keeping in memory was not a good idea. So I
decided that I'll keep a list of assets that the images are loaded
from, and the images will be loaded as needed and kept handy using
WeakReferences. The class that kept that list had a get() method for
loading the image.
So, my ListAdapter used this get() method, that would load the image
if necessary. As it was loaded, it was also added to internal cache.
And at this point, notifyChanged() was called on my ListAdapter. And
this was my problem, because whenever you would scroll the list, it
would result in something like that:
listAdapter.getItem();
get(); // this loads the image
addToCache(); // keep the image using WeakReference
listAdapter.notifyChanged(); // BAD
I'm actually surprised this did not result in infinite loop and a
force close. But it did do some bad things to the List.
My solution was to move the call to notifyChanged() somewhere else. It
didn't make sense to call it when adding images to cache in the first
place.
So I suggest you take a look at your ListAdapter implementation, trace
all the calls that are made and see if you don't end up calling
notifyChanged() at some point (or maybe doing something to the
ListView that would force it to do bad things).
Hope this helps.
Cheers,
Piotr
On Jul 1, 4:17 pm, Jalal <[email protected]> wrote:
> Hi Piotr,
>
> I'm facing exactly the sameproblem: untouchableGridViewitemsinside
> aDialog, they can only be clicked after gainfocuswith the
> TrackBall. Can you explain me better the solution you found? I didn't
> understand it. Thanks,
>
> Jalal
>
> On 9 jun, 19:09, Piotr Buła <[email protected]> wrote:
>
> > Just for the record, I resolved theproblem. Theproblemwas in
> > ListAdapter, or rather, the way it interacted with the rest of the
> > program. As a result, call to getItem() triggered unnecessary list
> > change notification, which caused this weird behavior.
>
> > Cheers,
> > Piotr
>
> > On 7 Cze, 19:44, Piotr Buła <[email protected]> wrote:
>
> > > H there,
>
> > > I have a littleproblemwith selecting items that are insideGridView
> > > that is displayedinsideadialog.
>
> > > What I want to achieve is adialogwindow that shows a grid of images
> > > that user can select (click on them) and some action is executed. I
> > > figured I'd just create aGridViewbacked by ListAdapter and set that
> > > on theDialog. But that causes some problems. Once you scroll the list
> > > of images, they becomeunselectable. Using trackball brings the
> > > selection back to the items and they become clickable again, until you
> > > scroll the list. This really gives me a headache.
>
> > > Below is the code I use to create mydialog:
>
> > > GridViewmyView = newGridView(MyActivity.this);
> > > myView.setNumColumns(2);
> > > myView.setAdapter(myImages.getListAdapter());
> > > myView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
> > > @Override
> > > public void onItemClick(AdapterView<?> parent, View view,
> > > int position, long id) {
> > > Log.i(TAG, "onItemClick: ");
> > > }
>
> > > });
>
> > > DialogmyDialog = newDialog(MyActivity.this);
> > > myDialog.setTitle("My Cool Images");
> > > myDialog.setContentView(myView);
>
> > > return myDialog;
>
> > > Am I missing something here? The sample code from ApiDemos is not much
> > > different, except that it does not involve Dialogs, so I'm thinking it
> > > might be something related toDialogstuff.
>
> > > Cheers,
> > > Piotr
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en