开发者

how to shuffle Images in Android

In project 1 question & Its 4 Answer .

Here As question I want to take 1 image Randomaly & Its Answer 4 images Randomaly.

But Problem is that which image As question me take Randomaly It also want to take in Answer 4 images also contain question image

how t开发者_开发问答o this possible

Pls Reply


Here top is the Question & col1,col2,col3,col4 this r the Answers which r the Randomaly come

int num is the totally questions & d Answers

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);

After this int convert to String

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);

check condition through if loop

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

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

Same as 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]);
} } } } } } } }


This link here might be help.. It contains shuffle of 4 images and one text question. You can add the question with image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜