F
falkenauge05
Neues Mitglied
- 0
Ich habe bei meiner App ein Problem. Und zwar habe ich verschiedene Buttons, die zufällig verschiedene Hintergrundfarben erhalten, genau wie ein ImageView. Dabei soll überprüft werden, ob irgendein Button die selbe Farbe hat wie das ImageView. Ist dies nicht der Fall, so sollen neue Zufallswerte ausgegeben werden. Bei einem Klick auf einen Button wird seine Farbe entweder weiß, wenn der Button die gleiche Farbe hat wie das ImageView oder grau, wenn das nicht der Fall ist. Hat man nun auf alle Buttons geklickt, die dieselbe Farbe wie das ImageView haben, sollen wieder neue Zufallswerte vergeben werden. Und hier liegt der Hund begraben. Probiere ich meinen Code mit einem Emulator aus, so funktioniert das Ganze meistens, aber manchmal habe ich alle richtigen Buttons gedrückt und es werden trotzdem keine neuen Zufallszahlen ausgegeben.
//Die Methode wird bei jedem ButtonKlick ausgeführt
public void ueberpruefeFarben(){
ColorDrawable sd=(ColorDrawable) showColor.getBackground();
int colorId=sd.getColor();
ColorDrawable cdBtnEins= (ColorDrawable) btnEins.getBackground();
ColorDrawable cdBtnZwei= (ColorDrawable) btnZwei.getBackground();
ColorDrawable cdBtnDrei= (ColorDrawable) btnDrei.getBackground();
ColorDrawable cdBtnVier= (ColorDrawable) btnVier.getBackground();
ColorDrawable cdBtnEins2= (ColorDrawable) btnEins2.getBackground();
ColorDrawable cdBtnZwei2= (ColorDrawable) btnZwei2.getBackground();
ColorDrawable cdBtnDrei2= (ColorDrawable) btnDrei2.getBackground();
ColorDrawable cdBtnVier2= (ColorDrawable) btnVier2.getBackground();
ColorDrawable cdBtnEins3= (ColorDrawable) btnEins3.getBackground();
ColorDrawable cdBtnZwei3= (ColorDrawable) btnZwei3.getBackground();
ColorDrawable cdBtnDrei3= (ColorDrawable) btnDrei3.getBackground();
ColorDrawable cdBtnVier3= (ColorDrawable) btnVier3.getBackground();
ColorDrawable cdBtnEins4= (ColorDrawable) btnEins4.getBackground();
ColorDrawable cdBtnZwei4= (ColorDrawable) btnZwei4.getBackground();
ColorDrawable cdBtnDrei4= (ColorDrawable) btnDrei4.getBackground();
ColorDrawable cdBtnVier4= (ColorDrawable) btnVier4.getBackground();
int btnEinsColor=cdBtnEins.getColor();
int btnZweiColor=cdBtnZwei.getColor();
int btnDreiColor=cdBtnDrei.getColor();
int btnVierColor=cdBtnVier.getColor();
int btnEins2Color=cdBtnEins2.getColor();
int btnZwei2Color=cdBtnZwei2.getColor();
int btnDrei2Color=cdBtnDrei2.getColor();
int btnVier2Color=cdBtnVier2.getColor();
int btnEins3Color=cdBtnEins3.getColor();
int btnZwei3Color=cdBtnZwei3.getColor();
int btnDrei3Color=cdBtnDrei3.getColor();
int btnVier3Color=cdBtnVier3.getColor();
int btnEins4Color=cdBtnEins4.getColor();
int btnZwei4Color=cdBtnZwei4.getColor();
int btnDrei4Color=cdBtnDrei4.getColor();
int btnVier4Color=cdBtnVier4.getColor();
while(colorId != btnEinsColor && colorId != btnZweiColor && colorId != btnDreiColor && colorId != btnVierColor && colorId != btnEins2Color && colorId != btnZwei2Color &&
colorId != btnDrei2Color && colorId != btnVier2Color && colorId != btnEins3Color && colorId != btnZwei3Color && colorId != btnDrei3Color && colorId != btnVier3Color &&
colorId != btnEins4Color && colorId != btnZwei4Color && colorId != btnDrei4Color && colorId != btnVier4Color){
setRandomNumbers();
setzeFarben();
sd=(ColorDrawable) showColor.getBackground();
colorId=sd.getColor();
cdBtnEins= (ColorDrawable) btnEins.getBackground();
cdBtnZwei= (ColorDrawable) btnZwei.getBackground();
cdBtnDrei= (ColorDrawable) btnDrei.getBackground();
cdBtnVier= (ColorDrawable) btnVier.getBackground();
cdBtnEins2= (ColorDrawable) btnEins2.getBackground();
cdBtnZwei2= (ColorDrawable) btnZwei2.getBackground();
cdBtnDrei2= (ColorDrawable) btnDrei2.getBackground();
cdBtnVier2= (ColorDrawable) btnVier2.getBackground();
cdBtnEins3= (ColorDrawable) btnEins3.getBackground();
cdBtnZwei3= (ColorDrawable) btnZwei3.getBackground();
cdBtnDrei3= (ColorDrawable) btnDrei3.getBackground();
cdBtnVier3= (ColorDrawable) btnVier3.getBackground();
cdBtnEins4= (ColorDrawable) btnEins4.getBackground();
cdBtnZwei4= (ColorDrawable) btnZwei4.getBackground();
cdBtnDrei4= (ColorDrawable) btnDrei4.getBackground();
cdBtnVier4= (ColorDrawable) btnVier4.getBackground();
btnEinsColor=cdBtnEins.getColor();
btnZweiColor=cdBtnZwei.getColor();
btnDreiColor=cdBtnDrei.getColor();
btnVierColor=cdBtnVier.getColor();
btnEins2Color=cdBtnEins2.getColor();
btnZwei2Color=cdBtnZwei2.getColor();
btnDrei2Color=cdBtnDrei2.getColor();
btnVier2Color=cdBtnVier2.getColor();
btnEins3Color=cdBtnEins3.getColor();
btnZwei3Color=cdBtnZwei3.getColor();
btnDrei3Color=cdBtnDrei3.getColor();
btnVier3Color=cdBtnVier3.getColor();
btnEins4Color=cdBtnEins4.getColor();
btnZwei4Color=cdBtnZwei4.getColor();
btnDrei4Color=cdBtnDrei4.getColor();
btnVier4Color=cdBtnVier4.getColor();
}
}
Ich würde mich über eventuelle Hilfe sehr freuen, da ich wirklich keine Ahnung habe, wieso der Vorgang manchmal funktioniert und manchmal nicht.
Herzliche Grüße,
Falkenauge
PS: Ich weiß nicht, ob das der richtige Thread ist, aber das ist ja sozusagen ein Codeschnipsel
//Die Methode wird bei jedem ButtonKlick ausgeführt
public void ueberpruefeFarben(){
ColorDrawable sd=(ColorDrawable) showColor.getBackground();
int colorId=sd.getColor();
ColorDrawable cdBtnEins= (ColorDrawable) btnEins.getBackground();
ColorDrawable cdBtnZwei= (ColorDrawable) btnZwei.getBackground();
ColorDrawable cdBtnDrei= (ColorDrawable) btnDrei.getBackground();
ColorDrawable cdBtnVier= (ColorDrawable) btnVier.getBackground();
ColorDrawable cdBtnEins2= (ColorDrawable) btnEins2.getBackground();
ColorDrawable cdBtnZwei2= (ColorDrawable) btnZwei2.getBackground();
ColorDrawable cdBtnDrei2= (ColorDrawable) btnDrei2.getBackground();
ColorDrawable cdBtnVier2= (ColorDrawable) btnVier2.getBackground();
ColorDrawable cdBtnEins3= (ColorDrawable) btnEins3.getBackground();
ColorDrawable cdBtnZwei3= (ColorDrawable) btnZwei3.getBackground();
ColorDrawable cdBtnDrei3= (ColorDrawable) btnDrei3.getBackground();
ColorDrawable cdBtnVier3= (ColorDrawable) btnVier3.getBackground();
ColorDrawable cdBtnEins4= (ColorDrawable) btnEins4.getBackground();
ColorDrawable cdBtnZwei4= (ColorDrawable) btnZwei4.getBackground();
ColorDrawable cdBtnDrei4= (ColorDrawable) btnDrei4.getBackground();
ColorDrawable cdBtnVier4= (ColorDrawable) btnVier4.getBackground();
int btnEinsColor=cdBtnEins.getColor();
int btnZweiColor=cdBtnZwei.getColor();
int btnDreiColor=cdBtnDrei.getColor();
int btnVierColor=cdBtnVier.getColor();
int btnEins2Color=cdBtnEins2.getColor();
int btnZwei2Color=cdBtnZwei2.getColor();
int btnDrei2Color=cdBtnDrei2.getColor();
int btnVier2Color=cdBtnVier2.getColor();
int btnEins3Color=cdBtnEins3.getColor();
int btnZwei3Color=cdBtnZwei3.getColor();
int btnDrei3Color=cdBtnDrei3.getColor();
int btnVier3Color=cdBtnVier3.getColor();
int btnEins4Color=cdBtnEins4.getColor();
int btnZwei4Color=cdBtnZwei4.getColor();
int btnDrei4Color=cdBtnDrei4.getColor();
int btnVier4Color=cdBtnVier4.getColor();
while(colorId != btnEinsColor && colorId != btnZweiColor && colorId != btnDreiColor && colorId != btnVierColor && colorId != btnEins2Color && colorId != btnZwei2Color &&
colorId != btnDrei2Color && colorId != btnVier2Color && colorId != btnEins3Color && colorId != btnZwei3Color && colorId != btnDrei3Color && colorId != btnVier3Color &&
colorId != btnEins4Color && colorId != btnZwei4Color && colorId != btnDrei4Color && colorId != btnVier4Color){
setRandomNumbers();
setzeFarben();
sd=(ColorDrawable) showColor.getBackground();
colorId=sd.getColor();
cdBtnEins= (ColorDrawable) btnEins.getBackground();
cdBtnZwei= (ColorDrawable) btnZwei.getBackground();
cdBtnDrei= (ColorDrawable) btnDrei.getBackground();
cdBtnVier= (ColorDrawable) btnVier.getBackground();
cdBtnEins2= (ColorDrawable) btnEins2.getBackground();
cdBtnZwei2= (ColorDrawable) btnZwei2.getBackground();
cdBtnDrei2= (ColorDrawable) btnDrei2.getBackground();
cdBtnVier2= (ColorDrawable) btnVier2.getBackground();
cdBtnEins3= (ColorDrawable) btnEins3.getBackground();
cdBtnZwei3= (ColorDrawable) btnZwei3.getBackground();
cdBtnDrei3= (ColorDrawable) btnDrei3.getBackground();
cdBtnVier3= (ColorDrawable) btnVier3.getBackground();
cdBtnEins4= (ColorDrawable) btnEins4.getBackground();
cdBtnZwei4= (ColorDrawable) btnZwei4.getBackground();
cdBtnDrei4= (ColorDrawable) btnDrei4.getBackground();
cdBtnVier4= (ColorDrawable) btnVier4.getBackground();
btnEinsColor=cdBtnEins.getColor();
btnZweiColor=cdBtnZwei.getColor();
btnDreiColor=cdBtnDrei.getColor();
btnVierColor=cdBtnVier.getColor();
btnEins2Color=cdBtnEins2.getColor();
btnZwei2Color=cdBtnZwei2.getColor();
btnDrei2Color=cdBtnDrei2.getColor();
btnVier2Color=cdBtnVier2.getColor();
btnEins3Color=cdBtnEins3.getColor();
btnZwei3Color=cdBtnZwei3.getColor();
btnDrei3Color=cdBtnDrei3.getColor();
btnVier3Color=cdBtnVier3.getColor();
btnEins4Color=cdBtnEins4.getColor();
btnZwei4Color=cdBtnZwei4.getColor();
btnDrei4Color=cdBtnDrei4.getColor();
btnVier4Color=cdBtnVier4.getColor();
}
}
Ich würde mich über eventuelle Hilfe sehr freuen, da ich wirklich keine Ahnung habe, wieso der Vorgang manchmal funktioniert und manchmal nicht.
Herzliche Grüße,
Falkenauge
PS: Ich weiß nicht, ob das der richtige Thread ist, aber das ist ja sozusagen ein Codeschnipsel
Zuletzt bearbeitet: