简体   繁体   中英

Android Studio Java EditText Contains Words

For Android Studio: I would like to check if words are typed in 'edit text'. If so, then I will return a 'text view'.

I am having trouble figuring out the exact code to type.

For example, this is what I have:

 for (int i = 0; i < suiWords.length; i++) {
    if (editPost.contains(suiWords[i])) {
       msgHotline.setVisibility(View.VISIBLE);
       break;
       }
    }

"contains" is giving me an error message, so I know that is not the right code to use.

Does anyone know what command I need to use to check whether or not a certain word is typed?

Thanks for your help in advance!

Notes:

  • I already tried searching Google + Stack Overflow for an answer and no luck. If you found the link, please kindly post it here.

  • I am still a student.

试试这个: editPost.getText().toString().equals(suiWords[i])

Try this:

for (int i = 0; i < suiWords.length; i++) {
    if (editPost.getText().toString().contains(suiWords[i])) {
       msgHotline.setVisibility(View.VISIBLE);
       break;
    }
}

If you are trying to check, whether your EditText value contains a specific value, Then you can use these line of code. editText.getText().toString().contains("valueToCheck")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM