0

There are 2 array namely b1[],b2[]

public void compare(){
        a1=recyText.toString().replaceAll("\\s", "");
        a2=edit3.toString().replaceAll("\\s","");
        b1 = a1.split("");
        b2= a2.split("");
        for (int i = 0; i < b1.length; i++) {
            for (int j=0;j<b2.length;j++){
                if(b1[i].equals(b2[j])){
                    edit4.setText(edit4.getText()+b1[i]);

                }
            }
         }
       }

I want to compare likeb1[0]=b2[0],b1[1]=b2[1] and

if b1[i]=b2[j] ,

I want to change b[i] color to Red. I searched setspan but it works when start in int, end is int. How can i change the color that i want in array?

PradyumanDixit
  • 2,372
  • 2
  • 12
  • 20
Lia
  • 5
  • 3

1 Answers1

0

change like this it will change the background color

if(b1[i].equals(b2[j])){
                edit4.setText(edit4.getText()+b1[i]);
                edit4.setBackgroundColor(Color.RED);
            }

If u want to change font Color add this

if(b1[i].equals(b2[j])){
                edit4.setText(edit4.getText()+b1[i]);
                edit4.setTextColor(Color.RED);
            }
else {
                edit4.setText(edit4.getText()+b1[i]);
                edit4.setTextColor(Color.BLACK);
            }
PushpikaWan
  • 2,437
  • 3
  • 14
  • 23
  • Hi:) thank you again. I deleted public void compare {} And I add a1= ..... edit4.setText(edit4.getText()+b1[i]); into new SpeechService.Listener() {...public void run() { if (isFinal) { ... (here) ----> edit4 shows me Red any letters... Did I put the wrong place.? – Lia Oct 28 '18 at 10:44
  • Hi, I didn't get u. Can u update it in a question please – PushpikaWan Oct 28 '18 at 10:48
  • sorry, ummm.... if a1= Mynameiszoe and a2=MynameisLia ----> i want to make Mynameis(Red color)Lia(Black color) in edit 4 . But i tried that you gave me, it changed all color red. How can i fix? – Lia Oct 29 '18 at 09:36
  • I tried, but my application isn't responding... recyText is Textview, and edit3 is Editview . I am wondering if I can compare text view and adit view like that. – Lia Oct 29 '18 at 10:39
  • yeah u can compare it. Becaues you just compare text from both editText and textView. But can u share error u got ? – PushpikaWan Oct 29 '18 at 10:46
  • I had error(E/memtrack: Couldn't load memtrack module). And I found how to fix it. And It worked! Thanks! – Lia Oct 30 '18 at 03:07
  • @Lia Nice to hear it. Happy coding – PushpikaWan Oct 30 '18 at 04:26