lundi 24 octobre 2022

how to check if the random number exists in array

i am tring to check my random number exists in my array this is m array

int [] img ={R.drawable.im1,R.drawable.im2}

My function to update data and show it random

private void updateQuestion() {
int ranom_number = random.nextInt(img.length);
image.setImageResource(img[ranom_number]);

ton= MediaPlayer.create(BallActivity.this,Questions.audinb[ranom_number]);

ton.start();

}

this is m class, in my view i have a button i want when the random number is displaying the user if he click right the others button gone. if he clic next the all button are showing. if the last number of array is displaying the activity finish

public void onClick(View v) {
switch (v.getId()) {

    case R.id.btn1:
        if (ranom_number == img.length) {
            bravo = MediaPlayer.create(getApplicationContext(), R.raw.bravo);
            bravo.start();
            bt2.setVisibility(v.GONE);
       
        }else{
            bt1.setVisibility(v.VISIBLE);
            bt2.setVisibility(v.VISIBLE);
           
        }

        break;
    case R.id.btn2:
        if(ranom_number <= img.length-1){
            
        }
        break;

    case R.id.suiv:
      if(ranom_number <= imgnb.length-1) {
          updateQuestion();
      }else{
          Intent i = new Intent(BallActivity.this, NewActivity.class);
          BallActivity.this.finish();
          startActivity(i);
      }

}

But doesn't work thank you for helping




Aucun commentaire:

Enregistrer un commentaire