Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. public class Home extends AppCompatActivity {
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.activity_main);
  6. Button one = (Button) findViewById(R.id.b1);
  7. one.setOnClickListener(new View.OnClickListener() {
  8. @Override
  9. public void onClick(View v) {
  10. goToSecondActivity();
  11. }
  12. });
  13. Button two = (Button) findViewById(R.id.b2);
  14. two.setOnClickListener(new View.OnClickListener() {
  15. @Override
  16. public void onClick(View v) {
  17. finish();
  18. }
  19. });
  20. }
  21. private void goToSecondActivity() {
  22. Intent i = new Intent(this, SelectNumberOfPlayers.class);
  23. startActivity(i);
  24. }
  25. }
  26.  
  27. SelectNumberOfPlayers.java
  28.  
  29. Taking only the numbers from the input and passing it to StartGame.class
  30.  
  31. public class SelectNumberOfPlayers extends AppCompatActivity {
  32.  
  33. EditText numberOfPlayers;
  34. Button three;
  35. @Override
  36. protected void onCreate(Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38. setContentView(R.layout.enter_number_of_players);
  39. three = (Button) findViewById(R.id.button3);
  40. three.setOnClickListener(new View.OnClickListener(){
  41.  
  42. public void onClick(View v){
  43.  
  44. String txt = numberOfPlayers.getText().toString();
  45. Intent i = new Intent(getApplicationContext(), StartGame.class);
  46. i.putExtra("players", txt);
  47. startActivity(i);
  48. }
  49. });
  50. }
  51. }
  52.  
  53. StartGame.java
  54.  
  55. public class StartGame extends AppCompatActivity {
  56.  
  57. @Override
  58. protected void onCreate(Bundle savedInstanceState) {
  59. super.onCreate(savedInstanceState);
  60. setContentView(R.layout.start_game);
  61.  
  62. Intent i = getIntent();
  63.  
  64. TextView numOfPlayersVal = (TextView) findViewById(R.id.txt2);
  65. numOfPlayersVal.setText(i.getStringExtra("Player number"));
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement