private int createList( final int maxListCount, final int listStartOffset, final String searchValue, StringBuilder result, String type) { int itemsFound = 0; ArrayList<String> nameList = mVcardManager.getPhonebookNameList(mOrderBy); final int requestSize = nameList.size() >= maxListCount ? maxListCount : nameList.size(); final int listSize = nameList.size(); String compareValue = "", currentValue, tmpCurrentValue; if (D) Log.d( TAG, "search by " + type + ", requestSize=" + requestSize + " offset=" + listStartOffset + " searchValue=" + searchValue); if (type.equals("number")) { // query the number, to get the names ArrayList<String> names = mVcardManager.getContactNamesByNumber(searchValue); for (int i = 0; i < names.size(); i++) { compareValue = names.get(i).trim(); if (D) Log.d(TAG, "compareValue=" + compareValue); for (int pos = listStartOffset; pos < listSize && itemsFound < requestSize; pos++) { currentValue = nameList.get(pos); if (D) Log.d(TAG, "currentValue=" + currentValue); if (currentValue.startsWith(compareValue)) { itemsFound++; result.append("<card handle=\"" + pos + ".vcf\" name=\"" + currentValue + "\"" + "/>"); } } if (itemsFound >= requestSize) { break; } } } else { if (searchValue != null) { compareValue = searchValue.trim(); compareValue = compareValue.toLowerCase(); } for (int pos = listStartOffset; pos < listSize && itemsFound < requestSize; pos++) { currentValue = nameList.get(pos); tmpCurrentValue = currentValue.toLowerCase(); if (D) Log.d(TAG, "currentValue=" + currentValue); if (searchValue == null) { itemsFound++; result.append("<card handle=\"" + pos + ".vcf\" name=\"" + currentValue + "\"" + "/>"); } else { int sIndex = -1; do { tmpCurrentValue = tmpCurrentValue.substring(sIndex + 1); if (tmpCurrentValue.startsWith(compareValue)) { itemsFound++; result.append( "<card handle=\"" + pos + ".vcf\" name=\"" + currentValue + "\"" + "/>"); break; } sIndex = tmpCurrentValue.indexOf(' '); } while (sIndex > 0); } } } return itemsFound; }