0
我已經寫了autocompletetextview一些代碼自定義對話框box.When鍵入一些文字,文本搜索動態進入hashmap.This HashMap的是大線text.It works.But慢慢給我造成的。動態自動完成textview緩慢顯示,如何顯示更快?
AutoCompleteTextView searchText = (AutoCompleteTextView)searchDialog.findViewById(R.id.searchText);
if(searchText.getText()!=null){
// searchString = searchText.getText().toString().trim();
String[] autoList = getAutoCompletWords(searchText.getText().toString().trim());
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ctx,android.R.layout.simple_dropdown_item_1line,autoList);
searchText.setAdapter(adapter);
}
private String[] getAutoCompletWords(String text){
Set<String> wordsSet = new TreeSet<String>();
Pattern wordPattern = Pattern.compile("\\b"+text+"\\w+",Pattern.CASE_INSENSITIVE);
Matcher matcher = wordPattern.matcher(bookContentMap.values().toString());
while(matcher.find()){
wordsSet.add(matcher.group());
}
String[] wordsArray = wordsSet.toArray(new String[0]);
return wordsArray;
}
如果我採取上面的代碼是給我線程處理器exception.Please給我上autocomplettext列表的快速響應的想法線程。
Rajendar是
其實iam使用treeset來排序項目,同時避免重複 – ADIT 2010-11-08 12:55:58
@ user486216噢好吧。創建字符串也可能相當密集。我會編輯並添加 – 2010-11-08 13:00:45