How do I make my Android app generate a random number?

I'm new to Java and making android applications. How do you make a Java program that rolls a number of dice based on what the user entered?

The Java program I created only rolls one dice.

How do you get Java to roll randomly from one to six?

How do you get Java to make random numbers based on the number of times the user wants?

Lastly, how do you get Java to draw a image based on the number the user entered?

Here what my application looks like.

Valid XHTML .

Here's my code

package com.warhammerdicerrolleralpha;

import java.util.Random;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class myMain extends Activity 
{
    /** Called when the activity is first created. 
     * @return */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);



     final Random myRandom = new Random(6);



    Button buttonGenerate = (Button)findViewById(R.id.button1);
    final TextView textGenerateNumber = (TextView)findViewById(R.id.text4);




    buttonGenerate.setOnClickListener(new OnClickListener()
    {

           @Override
           public void onClick(View v) 
           {
            // TODO Auto-generated method stub
            textGenerateNumber.setText(String.valueOf(myRandom.nextInt()));
           }});

    }

}

My xml file:





    
    
    
    
    


5
задан Glorfindel 9 August 2019 в 09:27
поделиться