我在自定义对话框中为autocompletetextview编写了一些代码。当键入一些文本时,文本会动态搜索到hashmap。这个hashmap是大行的文本。它很有用。但是慢慢给我结果。
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;
}
如果我为上面的代码提取线程,它会给我线程处理程序异常。请给我一个关于autocomplettext上列表快速响应的想法。
Rajendar是
答案 0 :(得分:0)
要确定哪些位快,哪些位慢,您需要使用Android's profiler。以下是值得研究的两件事,它们可能是最大的资源消耗: