2016-04-20 2 views
-3

Я хочу сказать: «Искать имя пользователя или номер пользователя, но это не работает:Нужна помощь с Android || Оператор

if (wp.getName().toLowerCase(Locale.getDefault()) 
    .contains(charText)) || (wp.getPhone().toLowerCase(Locale.getDefault()) 
    .contains(charText)) 

Любые идеи о том, как я мог бы получить эту работу? Вот мой полный код:

public void filter(String charText) { 
      charText = charText.toLowerCase(Locale.getDefault()); 
    //  _data is our list of contacts 
      _data.clear(); 
    //  If there is nothing in the searchview, if the charText length is 0, 
    //  then show all the contacts 
      if (charText.length() == 0) { 
       _data.addAll(arraylist); 
    //   or else.... 
      } else { 
       for (SelectContact wp : arraylist) { 
    //    If a contact's name matches the input thus far, which is charText, or their number matches it, 
    //    then include it in the listview. 
        if (wp.getName().toLowerCase(Locale.getDefault()) 
          .contains(charText)) || (wp.getPhone().toLowerCase(Locale.getDefault()) 
          .contains(charText)) 
         { 

          _data.add(wp); 
         } 
       } 
      } 
      notifyDataSetChanged(); 
     } 
+2

Приложите ВСЕ ваши, если condidtion внутри скобок 'if ((...) || (...))'. Теперь это 'if (...) || (...) ', который не будет работать. –

ответ

1

Как Боб Malooga отметил в своем комментарии выше, всегда заключите весь из ваших, если условие в скобках, как этот

if (put the whole condition of what your looking out for in here) 
{do stuff} 
Смежные вопросы