Thursday, January 12, 2012

[android-developers] Re: Using an adapter from another class/activity

Thanks. How would I use this model for ArrayAdapters across several
activities?

Currently, I define my ArrayAdapter class in 1 .java file, declare/
initialize it in my main activity's onCreate() method, generate the
list that binds to the adapter in a background thread in my main
activity (this takes up to half a minute), and starts a Runnable in
the UI thread to call notifyDataSetchanged() to update the adapter
once the list generation has completed.

Meanwhile, the other activities run their own background threads that
wait for the main activity's background thread to notify them of list
generation completion, then in the UI thread filters the adapter to
get specific subsets of the full list and displays them in their
activities.

I've some problems with this approach:

1. It seems too complicated - I'm creating 1 thread for each activity,
which then starts a Runnable in the UI thread to access the adapter
(accessing the adapter from the background threads lead to runtime
errors).
2. I get occasional force closes with the following error message in
logcat: "The content of the adapter has changed but ListView did not
receive a notification. Make sure the content of your adapter is not
modified from a background thread, but only from the UI thread."

On Jan 12, 10:55 am, Kristopher Micinski <krismicin...@gmail.com>
wrote:
> On Wed, Jan 11, 2012 at 9:46 PM,galapogos<gois...@gmail.com> wrote:
> > Hi,
>
> > I'm not aware of the singleton model. Are there any guides for it?
>
> > Thanks.
>
> the "singleton model" refers to a so called "design pattern" ..., You
> can google it to find good examples:
>
> http://en.wikipedia.org/wiki/Singleton_pattern

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate