我想说,'搜索用户的名字或用户的号码,但这不起作用:
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();
}
答案 0 :(得分:1)
正如鲍勃·马洛加在上面的评论中指出的那样,总是将你的if条件的整个括在括号中,比如
if (put the whole condition of what your looking out for in here)
{do stuff}