samedi 21 mai 2016

Stop previous random activity from showing

Does anyone know how to completely stop the random activity from showing? I have 5 classes with 10 questions each. Once the correct answer is given I want to move on to the next random class and not have the previous class come up again. Once all the random classes are answered the first time, then the Random method has ended. I tried finish() but that doesn't work. On button click I still get repeated classes after it has already been answered. Please see my code and advise if you could. Thx

public class HomeActivity extends AppCompatActivity {

TextView myTv;
Button nextBtn;
EditText myEt;
Button playgameBtn;

int mCounter = 0;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    myTv = (TextView) findViewById(R.id.myTv);
    nextBtn = (Button) findViewById(R.id.nextBtn);
    playgameBtn = (Button) findViewById(R.id.playgameBtn);
    myEt = (EditText) findViewById(R.id.myEt);


   final String[] clazzes = new String[] {"Mark.class", "John.class", "Caleb.class", "Isaiah.class", "Jacob.class"};


    playgameBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ArrayList<Class> activityList = new ArrayList<>();
            activityList.add(Mark.class);
            activityList.add(John.class);
            activityList.add(Caleb.class);
            activityList.add(Isaiah.class);
            activityList.add(Jacob.class);


            Random generator = new Random();
            int number = generator.nextInt(5)*1;

            Class activity = null;

            switch (number){
                case 1:
                    activity = John.class;
                    break;
                case 2:
                    activity = Caleb.class;
                    break;
                case 3:
                    activity = Mark.class;
                    break;
                case 4:
                    activity = Isaiah.class;
                    break;
                default:
                    activity = Jacob.class;
                    break;


            }
            Intent intent = new Intent(getBaseContext(), activity);



             startActivity(intent);
            finish();

            }

private void finish() {
}


    });


      }



  }




Aucun commentaire:

Enregistrer un commentaire