嘿伙计我需要我的搜索功能才能像联系人那样行事。我正从服务器检索我的参与者列表,并在用户搜索结果时重建它。胡佛我只能在他们输入完整的名字时才能使用它。让我告诉你我的代码。我尝试了很多组合。任何的想法?这是儿童饥饿联盟的捐赠应用程序。 =]
这只是在for循环中添加每个名称fyi
if (searchQ.contains(child.first_name.toLowerCase())
|| searchQ.matches(child.last_name.toLowerCase()) {
id = child.id;
addChildToList(child);
}
if (searchQ.matches("")){
addChildToList(child);
}
这是我的textwatcher
public void searchChild(){
final EditText ET = (EditText) findViewById(R.id.search);
// create the TextWatcher
TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
// Rebuilds the list
String searchQ = ET.getText().toString();
getChildrenListSearch(searchQ);
}
@Override
public void afterTextChanged(Editable editable) {
// Remove rows that do no match
TableLayout tl = (TableLayout)findViewById(R.id.childList);
tl.removeAllViews();
}
};
//we must add the textWatcher to our EditText
ET.addTextChangedListener(textWatcher);
}
答案 0 :(得分:1)
其他方式...
if (searchQ.contains(child.first_name.toLowerCase())
|| searchQ.matches(child.last_name.toLowerCase()) {
id = child.id;
addChildToList(child);
}
到此......
if (child.first_name.toLowerCase().contains(searchQ)
|| searchQ.matches(child.last_name.toLowerCase()) {
id = child.id;
addChildToList(child);
}