WEB开发网
开发学院手机开发Android 开发 通过改写ArrayAdapter 用AutoCompleteTextView 实... 阅读

通过改写ArrayAdapter 用AutoCompleteTextView 实现汉字和拼音双向关联

 2010-07-15 20:43:00 来源:WEB开发网   
核心提示:mOriginalValues = new ArrayList(mObjects);}}if (prefix == null || prefix.length() == 0) {synchronized (mLock) {ArrayList list = new ArrayList(mOriginalValues);r

mOriginalValues = new ArrayList(mObjects);

}

}

if (prefix == null || prefix.length() == 0) {

synchronized (mLock) {

ArrayList list = new ArrayList(mOriginalValues);

results.values = list;

results.count = list.size();

}

} else {

String prefixString = prefix.toString().toLowerCase();

final ArrayList values = mOriginalValues;

final int count = values.size();

final ArrayList newValues = new ArrayList(count);

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")

上一页  3 4 5 6 7 8 9  下一页

Tags:通过 改写 ArrayAdapter

编辑录入:coldstar [复制链接] [打 印]
赞助商链接