Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.tictactoe;
- import android.content.Context;
- import android.graphics.Color;
- import android.view.Gravity;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.*;
- public class Board extends LinearLayout implements View.OnClickListener{
- Button [][]btns = new Button[3][3];
- Button btnResetGame;
- LinearLayout l;
- TextView tvWIn;
- public Board(Game m)
- {
- super(m.context);
- l = new LinearLayout(m.context);
- LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- layoutParams.gravity = Gravity.CENTER_VERTICAL;
- l.setLayoutParams(layoutParams);
- l.setOrientation(VERTICAL);
- l.setWeightSum(100);
- TextView tv1 = new TextView(m.context);
- LayoutParams tv1_params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0);
- tv1_params.gravity = Gravity.CENTER;
- tv1_params.weight = 20;
- tv1.setLayoutParams(tv1_params);
- tv1.setGravity(Gravity.CENTER);
- tv1.setText("Welcome to tic tac toe");
- l.addView(tv1);
- TableLayout tl;
- tl = new TableLayout(m.context);
- LayoutParams tlParam = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- tlParam.weight = 60;
- tl.setLayoutParams(tlParam);
- tl.setWeightSum(3);
- for(int i=0;i<3;i++)
- {
- TableRow tl_row = new TableRow(m.context);
- LayoutParams tl_row_params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
- tl_row_params.weight = 1;
- tl_row.setLayoutParams(tl_row_params);
- tl_row.setWeightSum(3);
- for(int j=0;j<3;j++)
- {
- Button btn=new Button(m.context);
- btn.setText(String.valueOf(i));
- LayoutParams btnParam=new LayoutParams(1,ViewGroup.LayoutParams.MATCH_PARENT);
- btn.setLayoutParams(btnParam);
- btnParam.weight = 1;
- tl_row.addView(btn);
- btn.setOnClickListener(this);
- btns[i][j] = btn;
- }
- tl.addView(tl_row);
- }
- l.addView(tl);
- m.addView(l);
- }
- @Override
- public void onClick(View v) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement