Code example for Cursor

Methods: getIntgetString

1
        mContactAccessor = ContactAccessor.getInstance();
    } 
 
    @Override 
    public final CharSequence convertToString(Cursor cursor) {
        String name = cursor.getString(RecipientsAdapter.NAME_INDEX);
        int type = cursor.getInt(RecipientsAdapter.TYPE_INDEX);
        String number = cursor.getString(RecipientsAdapter.NUMBER_INDEX).trim();
 
        String label = cursor.getString(RecipientsAdapter.LABEL_INDEX);
        CharSequence displayLabel = mContactAccessor.phoneTypeToString(mContext, type, label);
 
        if (number.length() == 0) {
            return number;
        } 
 
        if (name == null) {
            name = "";
        } else { 
            // Names with commas are the bane of the recipient editor's existence. 
            // We've worked around them by using spans, but there are edge cases 
            // where the spans get deleted. Furthermore, having commas in names 
            // can be confusing to the user since commas are used as separators 
            // between recipients. The best solution is to simply remove commas 
            // from names. 
            name = name.replace(", ", " ")
                       .replace(",", " ");  // Make sure we leave a space between parts of names.
        } 
 
        String nameAndNumber = RecipientsFormatter.formatNameAndNumber(name, number);
 
        SpannableString out = new SpannableString(nameAndNumber);
        int len = out.length();
 
        if (!TextUtils.isEmpty(name)) {
            out.setSpan(new Annotation("name", name), 0, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else { 
            out.setSpan(new Annotation("name", number), 0, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } 
 
        String person_id = cursor.getString(RecipientsAdapter.CONTACT_ID_INDEX);
        out.setSpan(new Annotation("person_id", person_id), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        out.setSpan(new Annotation("label", displayLabel.toString()), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);              
        out.setSpan(new Annotation("number", number), 0, len,
Experience pair programming with AI  Get Codota for Java