Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.79 KB | None | 0 0
  1. package com.example.wojciech.kolko2;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.util.DisplayMetrics;
  6. import android.widget.Button;
  7. import android.widget.GridLayout;
  8. import android.widget.RelativeLayout;
  9.  
  10. import java.lang.reflect.Array;
  11. import java.util.ArrayList;
  12.  
  13. /**
  14.  * Created by wojciech on 25.03.17.
  15.  */
  16.  
  17. public class MainActivity extends Activity {
  18.  
  19.     RelativeLayout relativeLayout;
  20.  
  21.     int n=10;
  22.  
  23.     protected void onCreate(Bundle savedInstanceState) {
  24.  
  25.         super.onCreate(savedInstanceState);
  26.  
  27.         relativeLayout= (RelativeLayout)findViewById(R.id.main_activity_relative);
  28.  
  29.         setContentView(R.layout.relative_layout);
  30.  
  31.         GridLayout gridLayout=(GridLayout)findViewById(R.id.grid_layout1);
  32.  
  33.  
  34.         gridLayout.setColumnCount(n);
  35.         gridLayout.setRowCount(n);
  36.  
  37.         DisplayMetrics displayMetrics = new DisplayMetrics();
  38.         getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
  39.        
  40.         int height = displayMetrics.heightPixels;
  41.         int width = displayMetrics.widthPixels;
  42.  
  43.         int wymiarEkranu;
  44.  
  45.         if ((height>width)){wymiarEkranu=width;}
  46.         else {wymiarEkranu=height;}
  47.  
  48.  
  49.         RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(wymiarEkranu / (n+1),
  50.                 wymiarEkranu / (n+1));
  51.  
  52.  
  53.         for (int i = 0; i< n*n; i++){
  54.  
  55.             Button button= new Button(this);
  56.             button.setLayoutParams(params);
  57.  
  58.             String text= ("p"+i);
  59.  
  60.             button.setText(text);
  61.  
  62.             gridLayout.addView(button);
  63.            
  64.         }
  65.  
  66.  
  67.  
  68.     }
  69.  
  70.  
  71.     /*public void czyWygrano(){
  72.  
  73.         ArrayList<Integer> lista =new ArrayList<Integer>();
  74.  
  75.         int nr_buttona=7;
  76.         boolean czyJestWygrana;
  77.         int zliczanieElementow1=0;
  78.         int zliczanieElementow2=0;
  79.         int zliczanieElementow3=0;
  80.         int zliczanieElementow4=0;
  81.  
  82.  
  83.  
  84.         //
  85.         for (int i=0; i<n; i++){
  86.  
  87.             if ( (lista[nr_buttona+4*(i-1)]==(lista[nr_buttona])) && i!=nr_buttona){
  88.  
  89.                 zliczanieElementow1++;
  90.  
  91.             }
  92.  
  93.             if ((lista[nr_buttona+(((nr_buttona-(nr_buttona%n)))/n)+i]==(lista[nr_buttona]))  && (((nr_buttona-(nr_buttona%n))/n)+i)==nr_buttona){
  94.  
  95.                 zliczanieElementow2++;
  96.  
  97.             }
  98.  
  99.  
  100.             if ( lista[ (i+i*n) ] == lista[nr_buttona] ){
  101.                 zliczanieElementow3++;
  102.             }
  103.  
  104.             if ( lista[ (n-1-i)+i*n ] == lista[nr_buttona] ){
  105.                 zliczanieElementow4++;
  106.             }
  107.  
  108.         }
  109.  
  110.         if ( zliczanieElementow1==n-1 || zliczanieElementow2==n-1 || zliczanieElementow3==n-1 || zliczanieElementow4==n-1){
  111.  
  112.             return 1;
  113.  
  114.         }
  115.         else {
  116.             return 0;
  117.         }
  118.     }*/
  119.  
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement