marcin
marcin

Reputation: 399

Weird Behavior from ArrayAdapter

I have an android test project with two classes:

  1. AdapterTestActivity extends ListActivity -> http://pastebin.com/BreRSPj1
  2. MyAdapter extends ArrayAdapter -> http://pastebin.com/YUK4CRQq

From System.out.println() in MyAdapter I get this printout:

05-22 16:43:03.942: I/System.out(17943): test 1
05-22 16:43:03.942: I/System.out(17943): test 2
05-22 16:43:03.950: I/System.out(17943): test 3
05-22 16:43:04.098: I/System.out(17943): test 1 
05-22 16:43:04.098: I/System.out(17943): test 2
05-22 16:43:04.098: I/System.out(17943): test 3
05-22 16:43:04.106: I/System.out(17943): test 1
05-22 16:43:04.106: I/System.out(17943): test 2
05-22 16:43:04.106: I/System.out(17943): test 3

but I expected something like:

test 1
test 2
test 3

Does anyone know why? - thanks!

Upvotes: 0

Views: 87

Answers (2)

elgui
elgui

Reputation: 3323

and for your 2nd question, you may need to add :

    _adapter.notifyDataSetChanged();

after adding your "test 4"

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157457

It is not a strange behavior, but it is an implementation detail of the framework. There is no guarantee on which or order or how many time getView() is called.

Upvotes: 1

Related Questions