Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3.     TextView textView1,textView2,textView3,textView4;
  4.  
  5.     @Override
  6.     protected void onCreate(Bundle savedInstanceState) {
  7.         super.onCreate(savedInstanceState);
  8.         setContentView(R.layout.activity_main);
  9.  
  10.         final ArrayList<Integer> list = new ArrayList<>();
  11.         list.add(Color.parseColor("#ff1744"));
  12.         list.add(Color.parseColor("#4a148c"));
  13.         list.add(Color.parseColor("#1a237e"));
  14.         list.add(Color.parseColor("#00bcd4"));
  15.         list.add(Color.parseColor("#4caf50"));
  16.         list.add(Color.parseColor("#ffc107"));
  17.         list.add(Color.DKGRAY);
  18.         list.add(Color.YELLOW);
  19.         list.add(Color.MAGENTA);
  20.         list.add(Color.CYAN);
  21.  
  22.         textView1 = (TextView) findViewById(R.id.textView1);
  23.         textView2= (TextView) findViewById(R.id.textView2);
  24.         textView3 = (TextView) findViewById(R.id.textView3);
  25.         textView4 = (TextView) findViewById(R.id.textView4);
  26.  
  27.         final Random random = new Random();
  28.  
  29.         textView1.setOnClickListener(new View.OnClickListener() {
  30.             @Override
  31.             public void onClick(View v) {
  32.                     int color2 = random.nextInt(10);
  33.                     int color3 = random.nextInt(10);
  34.                     int color4 = random.nextInt(10);
  35.                     if (color2 == color3 || color2 == color4 || color3 == color4){
  36.                         color2 = random.nextInt(10);
  37.                         color3 = random.nextInt(10);
  38.                         color4 = random.nextInt(10);
  39.                     }
  40.                     textView2.setBackgroundColor(list.get(color2));
  41.                     textView3.setBackgroundColor(list.get(color3));
  42.                     textView4.setBackgroundColor(list.get(color4));
  43.  
  44.             }
  45.         });
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement