Incidentally, I also need to load and scale images within an Adapter.
I think I ended up implementing a separate thread to do this. This
allowed loading messages to be queued, consisting of a filename to
load and an ImageView reference which the loaded Bitmap is attached to
(that final bit occuring on the UI thread, of course).
On Apr 8, 4:55 pm, Valentin <[EMAIL PROTECTED]> wrote:
> Hello android enthusiasts,
>
> I noticed a pretty strange behavior today. It seems as if the number
> of executions of an overriden getView() methode (of
> SimpleCursorAdapter) is correlated to the number of LinearLayouts (the
> Spinner widget that uses this adapter) it is nested in.
>
> The following code illustrates this:
>
> ############################
> ####DemonstrateBug.java#####
> ############################
> public class DemonstrateBug extends Activity {
>
> @Override
> protected void onCreate(Bundle icicle) {
> super.onCreate(icicle);
> setContentView(R.layout.bug);
>
> String[] from = new String[] { People.NAME };
> int[] to = { R.id.tv_name };
>
> Cursor cursor = managedQuery(People.CONTENT_URI, new String[] {
> People._ID, People.NAME }, null, null);
>
> SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
> R.layout.in_spinner, cursor, from, to) {
> @Override
> public View getView(int position, View convertView, ViewGroup
> parent) {
> Log.d("BUG", "getView for posititon " + position);
> return super.getView(position, convertView, parent);
> }
> };
>
> Spinner s = (Spinner) findViewById(R.id.spinner);
> s.setAdapter(adapter);
> s.setSelection(2);
> }
>
> }
>
> ###############################
> ###res/layout/bug.xml############
> ###############################
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content" android:orientation="vertical">
> <LinearLayout android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:orientation="vertical">
> <LinearLayout android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:orientation="vertical">
> <Spinner android:id="@+id/spinner"
> android:layout_width="fill_parent"
> android:layout_height="fill_parent" />
> </LinearLayout>
> </LinearLayout>
> </LinearLayout>
>
> Output:
> ...
> D/ActivityThread( 5979): Installing external provider
> contacts;call_log:
> com.google.android.providers.contacts.ContactsProvider
> D/BUG ( 5979): getView for posititon 0
> D/BUG ( 5979): getView for posititon 0
> D/BUG ( 5979): getView for posititon 2
> ...
>
> Expected Output:
> ...
> D/ActivityThread( 5979): Installing external provider
> contacts;call_log:
> com.google.android.providers.contacts.ContactsProvider
> (maybe: "D/BUG ( 5979): getView for posititon 0" because of
> initialization)
> D/BUG ( 5979): getView for posititon 2
> ....
>
> If i nest another LinearLayout arround the Spinner, getView will be
> executed 4 times. After that I can nest as many Views as I like,
> getView will not be called more than 4 times.
>
> I have 2 problems with the bug:
> 1) I have a pretty complicated layout and I load and scale an image in
> getView. When getView is executed 4 times it takes pretty long
> (because the image will be scaled and loaded 4 times).
> 2) Even if I should not do resource intensive stuff in getView() it
> creates side effects because 1 time getView is called for the right
> position, the other times it is called for the first item in the
> spinner.
>
> I have a similar issue with ListView in a ListActivity. But it is
> harder to reproduce. I hope gaining insight in this behavior will
> reveal insight in the other one as well.
>
> Can you reproduce said behavior? Should I file a bug report?
>
> Bye bye,
> Valentin
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---