mardi 10 septembre 2019

random array android from string

I want to assign the numbers of my array at random to the keys key0, key1 etc ..

I'm using this code where in the first two lines I have my array, and with setText I assign the number. but i can't get it to work ..

            String[] shuffledKeys = {"0","1","2","3","4","5","6","7","8","9"};

        Random random = new Random(); // or create a static random field...
        String randString = shuffledKeys[random.nextInt(shuffledKeys.length)];

        key0.setText(shuffledKeys.get(0));
        key1.setText(shuffledKeys.get(0));
        key2.setText(shuffledKeys.get(0));
        key3.setText(shuffledKeys.get(0));
        key4.setText(shuffledKeys.get(0));
        key5.setText(shuffledKeys.get(0));
        key6.setText(shuffledKeys.get(0));
        key7.setText(shuffledKeys.get(9));
        key8.setText(shuffledKeys.get(8));
        key9.setText(shuffledKeys.get(9));




Aucun commentaire:

Enregistrer un commentaire