jeudi 7 janvier 2016

How to check if TextView contains certain word Android?

in my app I need to add a feature that detects if the Textview contains certain word and then it reacts to it accordingly, for example, if it contains the word 'boy' it will change the colour to blue and if it contains the word 'girl' it will change the colour to pink. The problem I am facing is that the textview will have multiple words of which one will be 'boy' or 'girl'. For example, 'Today the boy played football', 'The girl went swimming' etc..

if the textview contained only 'boy' or 'girl' then I could do something like;

String text = textView.getText().toString();
if(text.equal("girl") || ("Girl")) {
    //Do Somthing...
} 
else if(text.equal("boy") || ("Boy")){
    //Do something else
}

any help is welcomed, thanks.

Aucun commentaire:

Enregistrer un commentaire