-2

I am trying to show contact numbers separated by commas But i am not able to do it. Right now I am able to show them line by line.How to show them like 9999999999,8888888888....etc Below is my code snippet

 try {
            int pos = 0;
            for (Contact contact : contacts) {
                String displayName = contact.getPhone(0);
                result.append(displayName + ",");
                result.setSpan(new BulletSpan(15), pos, pos + displayName.length() + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                pos += displayName.length() + 1;
            }
        }
        catch (Exception e) {
            result.append(e.getMessage());
        }
Cœur
  • 34,719
  • 24
  • 185
  • 251

2 Answers2

1

you are getting next line because you are appending \n

To get comma separated replace "\n" with ","

String displayName = contact.getPhone(0);
                result.append(displayName + ",");
SpringLearner
  • 13,546
  • 20
  • 71
  • 113
1

\n used to print new line so put comma symbol (',') instead of \n

   result.append(contact.getPhone(0)+ ",");//for one person no 
Narender Reddy
  • 453
  • 5
  • 18