lundi 24 octobre 2016

generate 6 random numbers between 1 -25 using android studio [duplicate]

This question already has an answer here:

I am having a hard time to generate 6 random numbers between 1 -25 using android studio. I would like it to be displayed in one text box. Also I don't want to get 0 and no repeats...can anyone help

This is my coding:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import java.util.Random;

import static com.example.gbiondi.randomnumber.R.id.textView;

public class MainActivity extends AppCompatActivity {

    // Tracks the score for generateQuebec
    int generateQuebec=0;

    //Tracks the score for generateOntario
    int generateOntario=0;

    //Resets the points for both generateQuebec and generateOntario to 0
    int scoreView=0;


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

    }

    public void generateQuebec(View view)

    {
        Random rand=new Random();
        int generateQuebec=rand.nextInt(24) + 1;
        TextView myText=(TextView) findViewById(textView);
        String myString=String.valueOf(generateQuebec);
        myText.setText(myString);    }

     /**
     * Displays the given numbers for Quebec.
     *
     * @param view
     */
    public void displayForQuebec(int view) {
        int generateQuebec=0;
        displayForQuebec(generateQuebec);
        TextView scoreView=(TextView) findViewById(R.id.button);
        scoreView.setText(String.valueOf(generateQuebec));
    }


    /**
     * Resets the score to 0
     */
    public void resetScore(View view) {
        generateQuebec=0;
        TextView scoreView=(TextView) findViewById(R.id.textView);
        scoreView.setText(String.valueOf(generateQuebec));

    }


}




Aucun commentaire:

Enregistrer un commentaire