Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  2.  
  3.     TextView textView1, textView2, textView3, textView4;
  4.     Random random = new Random();
  5.     ArrayList<Integer> list = new ArrayList<>();
  6.  
  7.     @Override
  8.     protected void onCreate(Bundle savedInstanceState) {
  9.         super.onCreate(savedInstanceState);
  10.         setContentView(R.layout.activity_main);
  11.  
  12.         textView1 = (TextView) findViewById(R.id.textView1);
  13.         textView2 = (TextView) findViewById(R.id.textView2);
  14.         textView3 = (TextView) findViewById(R.id.textView3);
  15.         textView4 = (TextView) findViewById(R.id.textView4);
  16.  
  17.         textView1.setOnClickListener(this);
  18.         textView2.setOnClickListener(this);
  19.         textView3.setOnClickListener(this);
  20.         textView4.setOnClickListener(this);
  21.  
  22.     }
  23.  
  24.     @Override
  25.     public void onClick(View v) {
  26.  
  27.         list.add(R.color.colorRed);
  28.         list.add(R.color.colorPink);
  29.         list.add(R.color.colorPurple);
  30.         list.add(R.color.colorIndigo);
  31.         list.add(R.color.colorBlue);
  32.         list.add(R.color.colorCyan);
  33.         list.add(R.color.colorTeal);
  34.         list.add(R.color.colorLime);
  35.         list.add(R.color.colorYellow);
  36.         list.add(R.color.colorDeepOrange);
  37.  
  38.         int color1 = random.nextInt(10);
  39.         int color2 = random.nextInt(10);
  40.         int color3 = random.nextInt(10);
  41.         int color4 = random.nextInt(10);
  42.  
  43.  
  44.  
  45.         while (true) {
  46.             if (color1 != color2) {
  47.                 break;
  48.             } else {
  49.                 color2 = random.nextInt(10);
  50.             }
  51.         }
  52.         while (true) {
  53.             if (color3 != color2 && color3 != color1) {
  54.                 break;
  55.             } else {
  56.                 color3 = random.nextInt(10);
  57.             }
  58.         }
  59.         while (true) {
  60.             if (color4 != color2 && color4 != color3 && color4 != color1) {
  61.                 break;
  62.             } else {
  63.                 color4 = random.nextInt(10);
  64.             }
  65.         }
  66.         if (v == textView1) {
  67.             textView2.setBackgroundColor(getResources().getColor(list.get(color2)));
  68.             textView3.setBackgroundColor(getResources().getColor(list.get(color3)));
  69.             textView4.setBackgroundColor(getResources().getColor(list.get(color4)));
  70.         }
  71.         if (v == textView2) {
  72.             textView1.setBackgroundColor(getResources().getColor(list.get(color1)));
  73.             textView3.setBackgroundColor(getResources().getColor(list.get(color3)));
  74.             textView4.setBackgroundColor(getResources().getColor(list.get(color4)));
  75.         }
  76.         if (v == textView3) {
  77.             textView1.setBackgroundColor(getResources().getColor(list.get(color1)));
  78.             textView2.setBackgroundColor(getResources().getColor(list.get(color2)));
  79.             textView4.setBackgroundColor(getResources().getColor(list.get(color4)));
  80.         }
  81.         if (v == textView4) {
  82.             textView1.setBackgroundColor(getResources().getColor(list.get(color1)));
  83.             textView2.setBackgroundColor(getResources().getColor(list.get(color2)));
  84.             textView3.setBackgroundColor(getResources().getColor(list.get(color3)));
  85.  
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement