通过改写ArrayAdapter 用AutoCompleteTextView 实现汉字和拼音双向关联
2010-07-15 20:43:00 来源:WEB开发网mOriginalValues = new ArrayList
}
}
if (prefix == null || prefix.length() == 0) {
synchronized (mLock) {
ArrayList
results.values = list;
results.count = list.size();
}
} else {
String prefixString = prefix.toString().toLowerCase();
final ArrayList
final int count = values.size();
final ArrayList
for (int i = 0; i < count; i++) {
final T value = values.get(i);
final String valueText = value.toString().toLowerCase();
final T value2 = mObjects2.get(i);
final String valueText2 = value2.toString().toLowerCase();
//查找拼音
if(valueText2.startsWith(prefixString)){
newValues.add(value);
//查找汉字
}else if(valueText.startsWith(prefixString)){
newValues.add(value);
}else{
//添加汉字关联
final String[] words = valueText.split(" ");
final int wordCount = words.length;
for (int k = 0; k < wordCount; k++) {
if (words[k].startsWith(prefixString)) {
newValues.add(value);
break;
}
}
//添加拼音关联汉字
final String[] words2 = valueText2.split(" ");
final int wordCount2 = words2.length;
for (int k = 0; k < wordCount2; k++) {
if (words2[k].startsWith(prefixString)) {
newValues.add(value);
break;
}
}
}
}
results.values = newValues;
results.count = newValues.size();
}
return results;
}
@SuppressWarnings("unchecked")
Tags:通过 改写 ArrayAdapter
编辑录入:coldstar [复制链接] [打 印]更多精彩
赞助商链接