DiceActivity
This commit is contained in:
parent
7e23e9b29b
commit
531ebd6646
@ -2,16 +2,39 @@ package com.example.diceroller;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by thibaud on 20/04/17.
|
* Created by thibaud on 20/04/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DiceActivity extends Activity {
|
public class DiceActivity extends Activity implements View.OnClickListener {
|
||||||
|
|
||||||
|
private TextView textResult;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_dice);
|
setContentView(R.layout.activity_dice);
|
||||||
|
|
||||||
|
TextView textTitle = (TextView)findViewById(R.id.textTitle);
|
||||||
|
textTitle.setText("6-sided dice");
|
||||||
|
|
||||||
|
textResult = (TextView)findViewById(R.id.textResult);
|
||||||
|
textResult.setText("");
|
||||||
|
|
||||||
|
Button rollButton = (Button)findViewById(R.id.rollButton);
|
||||||
|
rollButton.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v){
|
||||||
|
Random rand = new Random();
|
||||||
|
int result = rand.nextInt(6) + 1;
|
||||||
|
this.textResult.setText(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.example.diceroller;
|
package com.example.diceroller;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@ -9,5 +12,23 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
Button button6 = (Button)findViewById(R.id.button6);
|
||||||
|
button6.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(MainActivity.this, DiceActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Button button20 = (Button)findViewById(R.id.button20);
|
||||||
|
button20.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(MainActivity.this, DiceActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
android:textSize="250sp"/>
|
android:textSize="250sp"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
android:id="@+id/rollButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/roll_dice"
|
android:text="@string/roll_dice"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user