Autore Topic: Listview e duplicazione dei dati  (Letto 405 volte)

Offline DX89B

  • Utente junior
  • **
  • Post: 121
  • Respect: +1
    • Mostra profilo
  • Dispositivo Android:
    HTC Desire
  • Play Store ID:
    Daniele Bonadiman
  • Sistema operativo:
    Mac OS X 10.6
Listview e duplicazione dei dati
« il: 08 Settembre 2010, 13:09:02 CEST »
0
Ho questo problema, quando nella mia ListView inserisco più di 8/9 items succede una cosa "strana", per esempio inserisco 72 elementi, so che è esagerato ma era per fare un test, mi fa il layout dei primi 8/9 elementi e li ripete scorrendo la lista per 72 volte ho inserito dei log nel codice  della getView dell adapter e questo è il risultato scorrendo la lista

item: è il numero degli oggetti presenti nell ArrayList dell'adapter.
id risorsa: è il codice univoco della risorsa.
position: è per l'appunto la position nella listView

ripeto ho scorso tutta la lista.

Codice: [Seleziona]
09-08 13:00:06.282: INFO/adapter(5157): item 72
09-08 13:00:06.282: INFO/adapter(5157): id risorsa 841
09-08 13:00:06.282: INFO/adapter(5157): position0
09-08 13:00:06.312: INFO/adapter(5157): item 72
09-08 13:00:06.312: INFO/adapter(5157): id risorsa 1506
09-08 13:00:06.312: INFO/adapter(5157): position1
09-08 13:00:06.342: INFO/adapter(5157): item 72
09-08 13:00:06.342: INFO/adapter(5157): id risorsa 1481
09-08 13:00:06.342: INFO/adapter(5157): position2
09-08 13:00:08.752: INFO/adapter(5157): item 72
09-08 13:00:08.752: INFO/adapter(5157): id risorsa 1492
09-08 13:00:08.752: INFO/adapter(5157): position3
09-08 13:00:08.782: INFO/adapter(5157): item 72
09-08 13:00:08.782: INFO/adapter(5157): id risorsa 1507
09-08 13:00:08.782: INFO/adapter(5157): position4
09-08 13:00:08.802: INFO/adapter(5157): item 72
09-08 13:00:08.802: INFO/adapter(5157): id risorsa 1509
09-08 13:00:08.802: INFO/adapter(5157): position5
09-08 13:00:08.822: INFO/adapter(5157): item 72
09-08 13:00:08.822: INFO/adapter(5157): id risorsa 1510
09-08 13:00:08.822: INFO/adapter(5157): position6
09-08 13:00:08.842: INFO/adapter(5157): item 72
09-08 13:00:08.842: INFO/adapter(5157): id risorsa 1508
09-08 13:00:08.842: INFO/adapter(5157): position7
09-08 13:00:16.822: INFO/adapter(5157): item 72
09-08 13:00:16.822: INFO/adapter(5157): id risorsa 3986
09-08 13:00:16.822: INFO/adapter(5157): position8

Edit:

ho messo position in un posto più furbo(prima linea della getView e questo è il risultato
Codice: [Seleziona]
09-08 13:10:41.612: INFO/adapter(5333): position0
09-08 13:10:41.612: INFO/adapter(5333): item 72
09-08 13:10:41.612: INFO/adapter(5333): id risorsa 841
09-08 13:10:41.642: INFO/adapter(5333): position1
09-08 13:10:41.642: INFO/adapter(5333): item 72
09-08 13:10:41.642: INFO/adapter(5333): id risorsa 1506
09-08 13:10:41.672: INFO/adapter(5333): position2
09-08 13:10:41.672: INFO/adapter(5333): item 72
09-08 13:10:41.672: INFO/adapter(5333): id risorsa 1481
09-08 13:10:50.762: INFO/adapter(5333): position0
09-08 13:10:50.772: INFO/adapter(5333): position1
09-08 13:10:50.772: INFO/adapter(5333): position2
09-08 13:10:50.772: INFO/adapter(5333): position3
09-08 13:10:50.772: INFO/adapter(5333): item 72
09-08 13:10:50.772: INFO/adapter(5333): id risorsa 1492
09-08 13:10:50.802: INFO/adapter(5333): position4
09-08 13:10:50.802: INFO/adapter(5333): item 72
09-08 13:10:50.802: INFO/adapter(5333): id risorsa 1507
09-08 13:10:50.823: INFO/adapter(5333): position5
09-08 13:10:50.823: INFO/adapter(5333): item 72
09-08 13:10:50.823: INFO/adapter(5333): id risorsa 1509
09-08 13:10:50.842: INFO/adapter(5333): position6
09-08 13:10:50.842: INFO/adapter(5333): item 72
09-08 13:10:50.842: INFO/adapter(5333): id risorsa 1510
09-08 13:10:50.872: INFO/adapter(5333): position7
09-08 13:10:50.872: INFO/adapter(5333): item 72
09-08 13:10:50.872: INFO/adapter(5333): id risorsa 1508
09-08 13:10:52.605: INFO/adapter(5333): position8
09-08 13:10:52.605: INFO/adapter(5333): item 72
09-08 13:10:52.605: INFO/adapter(5333): id risorsa 3986
09-08 13:10:52.702: INFO/adapter(5333): position9
09-08 13:10:52.782: INFO/adapter(5333): position10
09-08 13:10:52.872: INFO/adapter(5333): position11
09-08 13:10:52.923: INFO/adapter(5333): position12
09-08 13:10:53.012: INFO/adapter(5333): position13
09-08 13:10:53.173: INFO/adapter(5333): position14
09-08 13:10:53.293: INFO/adapter(5333): position15
09-08 13:10:53.472: INFO/adapter(5333): position16
09-08 13:10:54.523: INFO/adapter(5333): position17
09-08 13:10:54.603: INFO/adapter(5333): position18
09-08 13:10:54.693: INFO/adapter(5333): position19
09-08 13:10:54.742: INFO/adapter(5333): position20
09-08 13:10:54.803: INFO/adapter(5333): position21
09-08 13:10:54.852: INFO/adapter(5333): position22
09-08 13:10:54.882: INFO/adapter(5333): position23
09-08 13:10:54.942: INFO/adapter(5333): position24
09-08 13:10:55.012: INFO/adapter(5333): position25
09-08 13:10:55.082: INFO/adapter(5333): position26
09-08 13:10:55.152: INFO/adapter(5333): position27
09-08 13:10:55.222: INFO/adapter(5333): position28
09-08 13:10:55.292: INFO/adapter(5333): position29
09-08 13:10:55.382: INFO/adapter(5333): position30
09-08 13:10:55.492: INFO/adapter(5333): position31
09-08 13:10:55.643: INFO/adapter(5333): position32
09-08 13:10:55.702: INFO/adapter(5333): position33
09-08 13:10:55.752: INFO/adapter(5333): position34
09-08 13:10:55.812: INFO/adapter(5333): position35
09-08 13:10:55.872: INFO/adapter(5333): position36
09-08 13:10:55.953: INFO/adapter(5333): position37
09-08 13:10:56.012: INFO/adapter(5333): position38
09-08 13:10:56.032: INFO/adapter(5333): position39
09-08 13:10:56.093: INFO/adapter(5333): position40
09-08 13:10:56.182: INFO/adapter(5333): position41
09-08 13:10:56.252: INFO/adapter(5333): position42
09-08 13:10:56.322: INFO/adapter(5333): position43
09-08 13:10:56.402: INFO/adapter(5333): position44
09-08 13:10:56.482: INFO/adapter(5333): position45
09-08 13:10:56.582: INFO/adapter(5333): position46
09-08 13:10:56.782: INFO/adapter(5333): position47
09-08 13:10:56.813: INFO/adapter(5333): position48
09-08 13:10:56.872: INFO/adapter(5333): position49
09-08 13:10:56.903: INFO/adapter(5333): position50
09-08 13:10:56.932: INFO/adapter(5333): position51
09-08 13:10:56.982: INFO/adapter(5333): position52
09-08 13:10:57.012: INFO/adapter(5333): position53
09-08 13:10:57.043: INFO/adapter(5333): position54
09-08 13:10:57.092: INFO/adapter(5333): position55
09-08 13:10:57.142: INFO/adapter(5333): position56
09-08 13:10:57.172: INFO/adapter(5333): position57
09-08 13:10:57.222: INFO/adapter(5333): position58
09-08 13:10:57.252: INFO/adapter(5333): position59
09-08 13:10:57.302: INFO/adapter(5333): position60
09-08 13:10:57.352: INFO/adapter(5333): position61
09-08 13:10:57.402: INFO/adapter(5333): position62
09-08 13:10:57.442: INFO/adapter(5333): position63
09-08 13:10:57.502: INFO/adapter(5333): position64
09-08 13:10:57.552: INFO/adapter(5333): position65
09-08 13:10:57.622: INFO/adapter(5333): position66
09-08 13:10:57.683: INFO/adapter(5333): position67
09-08 13:10:57.752: INFO/adapter(5333): position68
09-08 13:10:57.832: INFO/adapter(5333): position69
09-08 13:10:57.952: INFO/adapter(5333): position70
09-08 13:10:57.982: INFO/adapter(5333): position71

Edit:
Io e il mio andare nel panico troppo presto, :) quando finisco di scrivere il post sul forum di solito trovo la soluzione, ecco il problema dove stava :

Quando all'inizio della getView, per questioni di performance usavo
Codice (Java): [Seleziona]
 View v = convertView;
             if (v == null) {
                LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.resource, null);       
            }

avevo chiuso male la } . l'avevo chiusa dopo aver assegnato i nuovi valori alle varie TextView e ImageView
« Ultima modifica: 08 Settembre 2010, 13:25:34 CEST da DX89B »

Offline Ricky`

  • Amministratore
  • Utente storico
  • *****
  • Post: 3489
  • Respect: +507
    • Github
    • Google+
    • rciovati
    • Mostra profilo
Re:Listview e duplicazione dei dati
« Risposta #1 il: 08 Settembre 2010, 14:05:41 CEST »
0
Io e il mio andare nel panico troppo presto, :)

Effettivamente si dovrebbe aprire un thread solo quando non si sa più che strada intraprendere per risolvere il problema.