【发布时间】:2012-05-10 03:00:25
【问题描述】:
我有大约 29,000 条记录的记录集。我的屏幕包含用于搜索条件的 EditText 框和包含所有 29,000 条记录的列表视图。
通过使用列出的方式进行搜索需要时间,并且不会根据需要提供更少的输出。
我的 EditText 包含
final EditText txtSearchCity = (EditText) findViewById(R.id.edtCity);
txtSearchCity.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
aCountryIDTemp.clear();
aCityStateTemp.clear();
for (int i = 0; i < aCountryID.size(); i++) {
if (aCityState
.get(i)
.toLowerCase()
.contains(
txtSearchCity.getText().toString()
.toLowerCase())) {
aCountryIDTemp.add(aCountryID.get(i));
aCityStateTemp.add(aCityState.get(i));
}
}
BindList();
}
});
}
BindList() 方法将 arraylist aCityStateTemp 设置为适配器。 动态搜索和创建新 ArrayList 的任何其他方式。
【问题讨论】:
-
当编辑文本发生变化时,最好使用数据库并执行 LIKE 查询。
-
@Dharmendra 正在做同样的事情而不是这样做.. 但需要同样的时间..
-
@Vishal Khakhkhar 我正在使用自定义键盘输入edittext,但我在更快地按下按钮时遇到延迟我有1000多条记录。我如何改进请帮助