このコードを試しましたが、すべてのリスト項目を反復処理するには時間がかかりすぎます。
item_all
データベースから取得したデータを含むリストです。
et_Search.addTextChangedListener(new TextWatcher() {
int textlength;
long time = System.currentTimeMillis();
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
textlength = getSearchText().length();
item_filtered = new ArrayList<StockItem>();
long time = System.currentTimeMillis();
int i = 0;
do {
int startpost = 0;
int endpost = textlength;
boolean found;
do {
found = false;
if (getItemDesc(i).length() >= textlength
&& getSearchText().equalsIgnoreCase((String)getItemDesc(i).subSequence(startpost, endpost))) {
item_filtered.add(item_all.get(i));
found = true;
}
startpost++;
endpost++;
} while (endpost <= getItemDesc(i).length() && !found);
i++;
} while ((i < item_all.size()) && (item_filtered.size() <= 20));
Log.v("Time", "Time needed " + (System.currentTimeMillis() - time));
if (item_filtered.isEmpty())
AppendList(new ArrayList<StockItem>());
else
AppendList(item_filtered);
}
次に、LIKEを使用しようとしました
try {
String[] WHATYOUWANT = { "*" };
String WHERECLAUSE = KEY_DESCRIPTION + " LIKE '%" + textIinput + "%' " ;
String GROUPBY = null;
String HAVING = null;
String ORDERBY = KEY_ROWID + " ASC LIMIT 0,100 ";
cursor = mDb.query(DATABASE_TABLE, WHATYOUWANT, WHERECLAUSE, null, GROUPBY, HAVING, ORDERBY);
} catch (Exception e) {
e.printStackTrace();
}
それはうまく機能しますが、実際には私が望むことはしません。
私が欲しいのは、検索されたアイテムが入力と正確に一致することです。「abc」と入力したのですが、「ab」または「bc」のみ (「abc」ではありません) を含むアイテムは表示されたくありません。