Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set<Integer> uniqueNumbers1 = new HashSet<>();
- while (uniqueNumbers1.size() < 51) {
- uniqueNumbers1.add((int)(Math.random()*101));
- }
- List<Integer> randomNumbers1 = new ArrayList<>(uniqueNumbers1);
- TextView textView1 = (TextView) findViewById(R.id.textview1);
- textView1.setText(TextUtils.join(", ", randomNumbers1));
- Set<Integer> uniqueNumbers2 = new HashSet<>();
- while (uniqueNumbers2.size() < 51) {
- uniqueNumbers2.add((int)(Math.random()*101));
- }
- List<Integer> randomNumbers2 = new ArrayList<>(uniqueNumbers2);
- TextView textView2 = (TextView) findViewById(R.id.textview2);
- textView2.setText(TextUtils.join(", ", randomNumbers2));
- List<Integer> randomNumbers3 = new ArrayList<>(randomNumbers1);
- randomNumbers3.retainAll(randomNumbers2);
- for (Integer num : randomNumbers3) {
- int start1 = textView1.getText().toString().indexOf(num.toString());
- int end1 = start1 + num.toString().length();
- int start2 = textView2.getText().toString().indexOf(num.toString());
- int end2 = start2 + num.toString().length();
- Spannable spannable1 = new SpannableString(textView1.getText());
- spannable1.setSpan(new ForegroundColorSpan(Color.RED), start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- textView1.setText(spannable1);
- Spannable spannable2 = new SpannableString(textView2.getText());
- spannable2.setSpan(new ForegroundColorSpan(Color.RED), start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- textView2.setText(spannable2);
- }
- TextView textView3 = (TextView) findViewById(R.id.textview3);
- textView3.setText(TextUtils.join(", ", randomNumbers3));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement