5つのイメージビューからランダムにイメージビューを表示したいのですが、ユーザーが表示されたイメージビューをクリックすると、別のイメージビューが表示され、カウントが5に達するまでプロセスが繰り返されますが、コードは一度に複数のイメージビューを表示します。
私のコード:
public class Gamepage extends Activity
{
ImageView img,img1,img2,img3,img4;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.trygame);
img=(ImageView) findViewById(R.id.imageView2);
img1=(ImageView) findViewById(R.id.imageView3);
img2=(ImageView) findViewById(R.id.imageView4);
img3=(ImageView) findViewById(R.id.imageView5);
img4=(ImageView) findViewById(R.id.imageView6);
int choose;
int count=0;
choose=(int) (Math.random()*5);
while(count!=5)
{
switch(choose)
{
case 1:
img.setVisibility(View.VISIBLE);
img.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast toast= Toast.makeText(Gamepage.this, "caught!! ", 200);
toast.setGravity(Gravity.RIGHT, 10,10);
toast.show();
img.setVisibility(View.INVISIBLE);
return true;
}
});
//choose=(int) (Math.random()*5);
//count++;
break;
case 2:
img1.setVisibility(View.VISIBLE);
img1.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast toast= Toast.makeText(Gamepage.this, "caught!! ", 200);
toast.setGravity(Gravity.RIGHT, 10,10);
toast.show();
img1.setVisibility(View.INVISIBLE);
return true;
}
});
//choose=(int) (Math.random()*5);
//count++;
break;
case 3:
img2.setVisibility(View.VISIBLE);
img2.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast toast= Toast.makeText(Gamepage.this, "caught!! ", 200);
toast.setGravity(Gravity.RIGHT, 10,10);
toast.show();
img2.setVisibility(View.INVISIBLE);
return true;
}
});
//choose=(int) (Math.random()*5);
//count++;
break;
case 4:
img3.setVisibility(View.VISIBLE);
img3.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast toast= Toast.makeText(Gamepage.this, "caught!! ", 200);
toast.setGravity(Gravity.RIGHT, 10,10);
toast.show();
img3.setVisibility(View.INVISIBLE);
return true;
}
});
//choose=(int) (Math.random()*5);
//count++;
break;
case 5:
img4.setVisibility(View.VISIBLE);
img4.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast toast= Toast.makeText(Gamepage.this, "caught!! ", 200);
toast.setGravity(Gravity.RIGHT, 10,10);
toast.show();
img4.setVisibility(View.INVISIBLE);
return true;
}
});
//choose=(int) (Math.random()*5);
// count++;
break;
default:
img4.setVisibility(View.VISIBLE);
img4.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast toast= Toast.makeText(Gamepage.this, "caught!! ", 200);
toast.setGravity(Gravity.RIGHT, 10,10);
toast.show();
img4.setVisibility(View.INVISIBLE);
return true;
}
});
//choose=(int) (Math.random()*5);
//count++;
break;
}
choose=(int) (Math.random()*5);
count++;
}
}
}