我使用 ArrayList
作为我的字典索引数据
我想做一个类似的搜索系统
例如
dictionary data : 'abcd' 'bcde' 'cdef' 'fghi' 'ijkl'
如果我搜索 'cd'
我想得到 index '3'
在我的资源中
for (String st : wordList) {
if (st.indexOf(searchWord) == 0) {
ListView.setSelection(index); //set listView scroll
break;
}
index++;
}
但是花了太多时间:(
制作这个系统的最佳方法是什么?
最佳答案
只需从循环中删除 index++ 并像这样更改 if(CONDITION)。
for (String st : wordList) {
if (st.startsWith(searchWord)) {
System.out.println("position="+wordlist.indexOf(st));//display index in log
ListView.setSelection(wordlist.indexOf(st)); //set listView scroll
break;
}
}
关于java - Android listView ArrayList 类似搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18287046/