onCreateDialog wird nicht immer aufgerufen

R

RED-BARON

Fortgeschrittenes Mitglied
19
Hallo Ihrs :D

hab da mal wieder ne Frage:

eine von ListActivity erbende Klasse überschreibt onCreateDialog und ruft
die Methode showDialog( ID ) auf.

In onCreateDialog werden die Dialoge ( ja, nein, abbrechen ) wie folgt erstellt:

Code:
[LEFT][SIZE=2][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AlertDialog.Builder(hbview.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2])[/SIZE][/SIZE][/LEFT]
 
[SIZE=2][SIZE=2].setIcon(R.drawable.[/SIZE]
[LEFT][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]alert_dialog_icon[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])[/SIZE][/LEFT]
 
[LEFT][SIZE=2].setTitle(settings.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]app[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].[/SIZE][I][U][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PatName[/COLOR][/SIZE][/COLOR][/SIZE][/U][/I][SIZE=2].subSequence(0, settings.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]app[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].[/SIZE][I][U][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PatName[/COLOR][/SIZE][/COLOR][/SIZE][/U][/I][SIZE=2].length()))[/SIZE][/LEFT]
 
[LEFT][SIZE=2].setView(textEntryView1)[/SIZE]

[SIZE=2].setPositiveButton(R.string.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]alert_dialog_start_hb[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] DialogInterface.OnClickListener() {[/SIZE][/LEFT]

 
 
 
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onClick(DialogInterface dialog, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] whichButton) {[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* User clicked OK so do some stuff */[/COLOR][/SIZE][/COLOR][/SIZE] [/LEFT]
 
[LEFT][SIZE=2]Intent intent = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Intent();[/SIZE]

[SIZE=2]intent.setClass(hbview.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], hbtodo.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE]
[LEFT][SIZE=2]startActivity(intent);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]})[/SIZE]
[SIZE=2].setNeutralButton(R.string.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]alert_dialog_show[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] DialogInterface.OnClickListener() {[/SIZE][/LEFT]
[/LEFT]

 
 
 
 
 
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onClick(DialogInterface dialog, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] whichButton) {[/SIZE][/LEFT]
 
 
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* User clicked Something so do some stuff */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
 
[LEFT][SIZE=2]settings.[/SIZE][/LEFT]
 

[LEFT][SIZE=2]Intent intent = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Intent();[/SIZE]
[LEFT][SIZE=2]intent.setClass(hbview.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], hbtodo.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE]
[SIZE=2]startActivity(intent); [/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]})[/SIZE]
[SIZE=2].setNegativeButton(R.string.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]alert_dialog_cancel[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] DialogInterface.OnClickListener() {[/SIZE][/LEFT]
[/LEFT]

 
 
 
 
 
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onClick(DialogInterface dialog, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] whichButton) {[/SIZE][/LEFT]
 
 
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* User clicked cancel so do some stuff */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
 
[LEFT][SIZE=2]dialog.dismiss();[/SIZE]

[SIZE=2]}[/SIZE]
[LEFT][SIZE=2]})[/SIZE]
[SIZE=2].create();[/SIZE][/LEFT]
[/LEFT]

 
 
 
 
 
[/SIZE]

Vor jedem Aufruf von showDialog wird settings.app.PatName
geändert

Wenn jetzt im Dialog der "negative" Button gedrückt wird ( abbrechen )
und der Dialog erneut aufgerufen wird erfolgt KEIN Ereignis "
onCreateDialog" erneut aufgerufen.

Wird eine der anderen beiden Möglichkeiten gewählt hingegen wird
onCreateDialog ausgelöst.

:eek:


Problem ist konkret, ich habe ne Liste mit Namen, beim anklicken
wird der Name aus der Liste mit im Dialog angezeigt, das funktioniert
nur beim ersten mal, wenn danach Abbrechen gedrückt wird kommt
in jedem anderen Dialog der zu erst angewählte Name...


Ich seh nur leider nicht den Grund, warum onCreateDialog nicht immer
aufgerufen wird :(

Hat wer dazu ne Idee ?
 
versuch mal die methode onPrepareDialog überschreiben.

oncreatedialog wird natürlich beim erzeugen des dialogs aufgerufen. wenn der dialog nicht mehr angezeigt wird, heißt das nicht, dass er nicht mehr exisitert.
 
naja ich würde nicht sagen, dass das ein problem ist

warum sollte ein dialog dauernd neu erzeugt werden, wenn er ja schon existiert? wäre ja sehr ressourcenverschwenderisch.

deshalb einfach über onPrepareDialog die werte austauschen. da wird eben nur zb ein text geändert und sonst muss nichts neu erzeugt werden
 
  • Danke
Reaktionen: RED-BARON

Ähnliche Themen

M
  • MikelKatzengreis
Antworten
10
Aufrufe
240
swa00
swa00
SaniMatthias
Antworten
19
Aufrufe
986
swa00
swa00
O
Antworten
15
Aufrufe
2.991
ORHUX
O
Zurück
Oben Unten