Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. package com.example.tictactoe;
  2.  
  3.  
  4. import android.content.Context;
  5. import android.graphics.Color;
  6. import android.view.Gravity;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.*;
  10.  
  11. public class Board extends LinearLayout implements View.OnClickListener{
  12.  
  13. Button [][]btns = new Button[3][3];
  14. Button btnResetGame;
  15. LinearLayout l;
  16. TextView tvWIn;
  17.  
  18. public Board(Game m)
  19. {
  20. super(m.context);
  21. l = new LinearLayout(m.context);
  22. LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  23. layoutParams.gravity = Gravity.CENTER_VERTICAL;
  24. l.setLayoutParams(layoutParams);
  25. l.setOrientation(VERTICAL);
  26. l.setWeightSum(100);
  27.  
  28. TextView tv1 = new TextView(m.context);
  29. LayoutParams tv1_params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0);
  30. tv1_params.gravity = Gravity.CENTER;
  31. tv1_params.weight = 20;
  32. tv1.setLayoutParams(tv1_params);
  33. tv1.setGravity(Gravity.CENTER);
  34. tv1.setText("Welcome to tic tac toe");
  35.  
  36. l.addView(tv1);
  37.  
  38. TableLayout tl;
  39. tl = new TableLayout(m.context);
  40. LayoutParams tlParam = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  41. tlParam.weight = 60;
  42. tl.setLayoutParams(tlParam);
  43. tl.setWeightSum(3);
  44.  
  45. for(int i=0;i<3;i++)
  46. {
  47. TableRow tl_row = new TableRow(m.context);
  48. LayoutParams tl_row_params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
  49. tl_row_params.weight = 1;
  50. tl_row.setLayoutParams(tl_row_params);
  51. tl_row.setWeightSum(3);
  52. for(int j=0;j<3;j++)
  53. {
  54. Button btn=new Button(m.context);
  55. btn.setText(String.valueOf(i));
  56. LayoutParams btnParam=new LayoutParams(1,ViewGroup.LayoutParams.MATCH_PARENT);
  57. btn.setLayoutParams(btnParam);
  58. btnParam.weight = 1;
  59. tl_row.addView(btn);
  60. btn.setOnClickListener(this);
  61. btns[i][j] = btn;
  62. }
  63. tl.addView(tl_row);
  64. }
  65. l.addView(tl);
  66. m.addView(l);
  67. }
  68. @Override
  69. public void onClick(View v) {
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement