-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
  • 37,241
  • 25
  • 195
  • 267

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,738
  • 20
  • 78
  • 116
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
  • 463
  • 6
  • 18