setItemChecked verhält sich seltsam (setzt zwei Einträge auf true)

M

muck

Ambitioniertes Mitglied
7
Hallo zusammen,

zwei Fragen zu setItemChecked:

1. Wie kann ich beim erstellen der ListView Einträge bereits anhacken? Die Info welche das sein müssen habe ich im Ergebnis meiner DB-Abfrage (ispoen):
Code:
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] showProductList() {[/SIZE]
[SIZE=2]Cursor productList = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dbConn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].rawQuery([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SELECT _id, count || unit || ' ' || name as sum, isopen FROM products WHERE irshoppinglists = ?"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] String[] {[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]strListID[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]});[/SIZE]
[SIZE=2]startManagingCursor(productList);[/SIZE][/LEFT]
 
[LEFT][SIZE=2]SimpleCursorAdapter productListAdapter = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] SimpleCursorAdapter ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]product_list_view[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], productList, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] String[] {[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"sum"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]}, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][] {R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text1[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]});[/SIZE]
[SIZE=2]setListAdapter(productListAdapter);[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]

2. Wenn ich einen Eintrag in der Liste anklicke, hackt er den darauffolgenden Eintrag ebenfalls an :blink: Ich mache lediglich:
Code:
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]protected[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onListItemClick(ListView lv, View v, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] pos, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] id) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onListItemClick(lv, v, pos, id);[/SIZE]
[SIZE=2]lv.setItemChecked(([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) id, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]

Im Voraus vielen Dank.
 
Zuletzt bearbeitet:
Also 2tens habe ich mal gelöst. Wenn man:
Code:
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]protected[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onListItemClick(ListView lv, View v, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] pos, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] id) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onListItemClick(lv, v, pos, id);[/SIZE]
[SIZE=2]lv.setItemChecked(([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) id, [COLOR=red][B]false[/B][/COLOR][/SIZE][SIZE=2]);[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]
aufruft, funktioniert es.
 
Zu früh gefreut. Jetzt ist es genau umgedreht. Es werden zwei deaktiviert :blink:

Das kann doch nicht so kompliziert sein. Ich klicke ein Item und es wird der hacken gesetzt oder rausgenommen. Was ist hier mal wieder nicht richtig dokumentiert in der Androidwelt, irgendein Flag das gesetzt werden muss damit das passiert was laut Doku passieren soll !?
 
Jetzt bin ich verwirrt.
Im Emulator geht es, aufm Handy nicht :blink:

Kann mir das einer erklären. Vielen Dank.
 
Dann spiel ich mal den Alleinunterhalter :thumbsup:

Ich komme der Sache näher:
Wenn die ListView das Attribut android:choiceMode="multipleChoice"
gesetzt hat muss lv.setItemChecked(id, false); in
onListItemClick () nicht aufgerufen werden, da er das an anderer Stelle (wo würde mich mal interessieren) wohl selbstständig macht.

So wie es aussieht passiert folgendes wenn ich setItem... ausführe:
1. In onListItemClick() setzt er das angeklickte item auf true
2. Der cursor wird versetzt
3. Die "interne" !? Routine für das ganze nochmla auf das nächste Item aus.

Sicher bin ich mir nicht, da es nicht immer das nächste ist.

Wo sind die Android Spezialisten, wer kann hier mal Licht ins dunkel bringen, die Googledoku gibt da nichts her. Oder liegts an am erstellen der Liste?
 

Ähnliche Themen

M
  • MikelKatzengreis
Antworten
5
Aufrufe
127
swa00
swa00
B
Antworten
4
Aufrufe
489
bb321
B
Zurück
Oben Unten