【问题标题】:How to check that whether words of arrayList are available in EditText in android如何检查arrayList的单词在android的EditText中是否可用
【发布时间】:2013-07-04 13:31:23
【问题描述】:

我有某些单词的 ArrayList:

ArrayList<String> words = new ArrayList<String>();
words.add("this");
words.add("that");  

我有 EditText :

EditText name = (EditText) findViewById(userName);

现在我想检查 arrayList 的单词是否在 name(EditText) 中可用:

Boolean WordsAvailable;
WordsAvailable = checkWords(name.getText().toString());

现在我想创建一个函数来检查 arrayList 的单词在 EditText 中是否可用,如下所示:

public Boolean checkWords(String checkString)
{
    for(int i=0;i<words.size();i++)
    {
         // Here i want to check that whether words of arrayList are available in EditText
         If ( word is available )
        {
         return YES;
        }
    }
    return NO;
} 

如何检查这种情况?

【问题讨论】:

    标签: java android arraylist android-edittext words


    【解决方案1】:

    你可以像这样使用 String.contains():

    public Boolean checkWords(String checkString)
    {
        for(String word : words)
        {
             if (checkString.contains(word))
             {
                 return YES;
             }
        }
        return NO;
    } 
    

    【讨论】:

    • 完美答案..谢谢。
    【解决方案2】:
    if(checkString.contains(words.get(i)))
    

    【讨论】:

      【解决方案3】:

      你也可以试试这个:

      if(checkString.equals(words.get(i))){
      
      
               return YES;
              }
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-09
        • 2021-12-12
        • 2011-11-03
        • 2012-11-21
        • 2017-12-28
        • 2020-09-11
        • 2021-04-26
        相关资源
        最近更新 更多