Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- TextView textView1,textView2,textView3,textView4;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final ArrayList<Integer> list = new ArrayList<>();
- list.add(Color.parseColor("#ff1744"));
- list.add(Color.parseColor("#4a148c"));
- list.add(Color.parseColor("#1a237e"));
- list.add(Color.parseColor("#00bcd4"));
- list.add(Color.parseColor("#4caf50"));
- list.add(Color.parseColor("#ffc107"));
- list.add(Color.DKGRAY);
- list.add(Color.YELLOW);
- list.add(Color.MAGENTA);
- list.add(Color.CYAN);
- textView1 = (TextView) findViewById(R.id.textView1);
- textView2= (TextView) findViewById(R.id.textView2);
- textView3 = (TextView) findViewById(R.id.textView3);
- textView4 = (TextView) findViewById(R.id.textView4);
- final Random random = new Random();
- textView1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- int color2 = random.nextInt(10);
- int color3 = random.nextInt(10);
- int color4 = random.nextInt(10);
- if (color2 == color3 || color2 == color4 || color3 == color4){
- color2 = random.nextInt(10);
- color3 = random.nextInt(10);
- color4 = random.nextInt(10);
- }
- textView2.setBackgroundColor(list.get(color2));
- textView3.setBackgroundColor(list.get(color3));
- textView4.setBackgroundColor(list.get(color4));
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement