嘿伙计们,我需要我的搜索功能来充当联系人。我正在从服务器检索我的参与者列表,并在用户搜索以获取结果时重建它。胡佛我只有在他们输入全名时才能让它工作。让我给你看我的代码。我尝试了很多组合。任何想法?这是儿童饥饿联盟的捐赠应用程序。=]
这只是在一个 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);
}
这是我的文本观察器
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);
}