2010-12-30 12 views
1

In Projekt 1 Frage & Sein 4 Antwort.wie man Bilder in Android mischt

Hier als Frage Ich möchte 1 Bild haben Zufällig & Seine Antwort 4 Bilder Zufällig.

Aber Problem ist, dass, welches Bild als Frage nehme ich randomaly Es soll auch in Antwort nehmen 4 Bilder enthalten auch Frage Bild

, wie dies möglich

Pls Antwort

Antwort

3

Hier oben ist die Frage & col1, col2, col3, col4 diese r die Antworten, die r die Randomaly kommen

int num ist die vollständige Fragen & d Antworten

int top,col1,col2,col3,col4,num=8; 

top=(int)Math.floor(Math.random()*num); 

col1=(int)Math.floor(Math.random()*num); 

col2=(int)Math.floor(Math.random()*num); 

col3=(int)Math.floor(Math.random()*num); 

col4=(int)Math.floor(Math.random()*num); 

Nach dieser int String konvertieren

String topstr, col1str, col2str, col3str, col4str;

topstr=String.valueOf(top); 
col1str=String.valueOf(col1); 
col2str=String.valueOf(col2); 
col3str=String.valueOf(col3); 
col4str=String.valueOf(col4); 

Prüfbedingung durch, wenn Schleife

hier Imageview imgtopcolor, imgcolortap1, imgcolortap2, imgcolortap3, imgcolortap4; hier int Toppickid [] = new int [num]; int Colpickid [] = neuer int [num];

Toppickid[0]=R.drawable.img0; 
//... 
Toppickid[7]=R.drawable.img7; 

Gleiche wie Colpickid []

if(topstr.equalsIgnoreCase(col1str) || topstr.equalsIgnoreCase(col2str) || topstr.equalsIgnoreCase(col3str) || topstr.equalsIgnoreCase(col4str)) 
     {if(!col1str.equalsIgnoreCase(col2str)) 
     { if(!col1str.equalsIgnoreCase(col3str)) 
     {if(!col1str.equalsIgnoreCase(col4str)) 
     {if(!col2str.equalsIgnoreCase(col3str)) 
     {if(!col2str.equalsIgnoreCase(col4str)) 
     {if(!col3str.equalsIgnoreCase(col4str)) 


{ 
    imgtopcolor.setImageResource(Toppickid[top]); 
    imgcolortap1.setImageResource(Colpickid[col1]); 
    imgcolortap2.setImageResource(Colpickid[col2]); 
    imgcolortap3.setImageResource(Colpickid[col3]); 
    imgcolortap4.setImageResource(Colpickid[col4]); 
} } } } } } } } 
1

Dieser Link here könnte hilfreich sein .. Es enthält Shuffle von 4 Bildern und einem Text Frage. Sie können die Frage mit Bild hinzufügen.

Verwandte Themen