How to split StringBuilder or print side by side
i'm developing an App in Android Studio and trying to send a list through email or WhatsApp. It's a list with product and quantity but it has to be side by side like:
product1 - quantity1
product2 - quantity2
product3 - quantity3
I tried in many ways but i can't get it to work side by side and the closest i got is code that i'm pasting here. it must go all the list at once. How can i do it???
fabShare = findViewById(R.id.fabShare);
fabShare.setOnClickListener(new View.OnClickListener( ) {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
sb.append(p);
String q = listaCompras2.get(i);
sb2.append(q);
}
intent.putExtra(Intent.EXTRA_TEXT, sb.toString() + "n" + sb2.toString());
startActivity(Intent.createChooser(intent, "share via"));
}
});
java

add a comment |
i'm developing an App in Android Studio and trying to send a list through email or WhatsApp. It's a list with product and quantity but it has to be side by side like:
product1 - quantity1
product2 - quantity2
product3 - quantity3
I tried in many ways but i can't get it to work side by side and the closest i got is code that i'm pasting here. it must go all the list at once. How can i do it???
fabShare = findViewById(R.id.fabShare);
fabShare.setOnClickListener(new View.OnClickListener( ) {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
sb.append(p);
String q = listaCompras2.get(i);
sb2.append(q);
}
intent.putExtra(Intent.EXTRA_TEXT, sb.toString() + "n" + sb2.toString());
startActivity(Intent.createChooser(intent, "share via"));
}
});
java

this wont work, whatsapp and other apps are going to break the lines the way they want... you didn't inject enough spaces to make over the differents product names length... whatsapp and major app fonts are not shell type, it means different letters have different sizes and it wont ever print the way you put on example
– Rafael Lima
Nov 19 '18 at 17:53
when making a propper question fill enough information to people help you, nobody will guess whatlisaCompras
is
– Rafael Lima
Nov 19 '18 at 17:54
add a comment |
i'm developing an App in Android Studio and trying to send a list through email or WhatsApp. It's a list with product and quantity but it has to be side by side like:
product1 - quantity1
product2 - quantity2
product3 - quantity3
I tried in many ways but i can't get it to work side by side and the closest i got is code that i'm pasting here. it must go all the list at once. How can i do it???
fabShare = findViewById(R.id.fabShare);
fabShare.setOnClickListener(new View.OnClickListener( ) {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
sb.append(p);
String q = listaCompras2.get(i);
sb2.append(q);
}
intent.putExtra(Intent.EXTRA_TEXT, sb.toString() + "n" + sb2.toString());
startActivity(Intent.createChooser(intent, "share via"));
}
});
java

i'm developing an App in Android Studio and trying to send a list through email or WhatsApp. It's a list with product and quantity but it has to be side by side like:
product1 - quantity1
product2 - quantity2
product3 - quantity3
I tried in many ways but i can't get it to work side by side and the closest i got is code that i'm pasting here. it must go all the list at once. How can i do it???
fabShare = findViewById(R.id.fabShare);
fabShare.setOnClickListener(new View.OnClickListener( ) {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
sb.append(p);
String q = listaCompras2.get(i);
sb2.append(q);
}
intent.putExtra(Intent.EXTRA_TEXT, sb.toString() + "n" + sb2.toString());
startActivity(Intent.createChooser(intent, "share via"));
}
});
java

java

edited Nov 19 '18 at 17:38
cricket_007
79.6k1142109
79.6k1142109
asked Nov 19 '18 at 17:29


Allan JaqueiraAllan Jaqueira
13
13
this wont work, whatsapp and other apps are going to break the lines the way they want... you didn't inject enough spaces to make over the differents product names length... whatsapp and major app fonts are not shell type, it means different letters have different sizes and it wont ever print the way you put on example
– Rafael Lima
Nov 19 '18 at 17:53
when making a propper question fill enough information to people help you, nobody will guess whatlisaCompras
is
– Rafael Lima
Nov 19 '18 at 17:54
add a comment |
this wont work, whatsapp and other apps are going to break the lines the way they want... you didn't inject enough spaces to make over the differents product names length... whatsapp and major app fonts are not shell type, it means different letters have different sizes and it wont ever print the way you put on example
– Rafael Lima
Nov 19 '18 at 17:53
when making a propper question fill enough information to people help you, nobody will guess whatlisaCompras
is
– Rafael Lima
Nov 19 '18 at 17:54
this wont work, whatsapp and other apps are going to break the lines the way they want... you didn't inject enough spaces to make over the differents product names length... whatsapp and major app fonts are not shell type, it means different letters have different sizes and it wont ever print the way you put on example
– Rafael Lima
Nov 19 '18 at 17:53
this wont work, whatsapp and other apps are going to break the lines the way they want... you didn't inject enough spaces to make over the differents product names length... whatsapp and major app fonts are not shell type, it means different letters have different sizes and it wont ever print the way you put on example
– Rafael Lima
Nov 19 '18 at 17:53
when making a propper question fill enough information to people help you, nobody will guess what
lisaCompras
is– Rafael Lima
Nov 19 '18 at 17:54
when making a propper question fill enough information to people help you, nobody will guess what
lisaCompras
is– Rafael Lima
Nov 19 '18 at 17:54
add a comment |
2 Answers
2
active
oldest
votes
You could use html, or you can literally insert new lines.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
sb
.append(listaCompras1.get(i))
.append(" - ")
.append(listaCompras2.get(i))
.append("n");
}
Rather than storing parallel String lists, though, it would be better if you had a single List<Compra>
Man, than you so much!!! It worked!!!
– Allan Jaqueira
Nov 19 '18 at 18:49
add a comment |
Try using the following :
StringJoiner joiner = new StringJoiner("n");
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
String q = listaCompras2.get(i);
joiner.add(p + " - " + q);
}
String result = joiner.toString();
A StringBuilder
could have been used like
sb.append(p).append(" - ").append(q).append("n");
in the loop but would have resulted in an extra newline at the end. The StringJoiner avoids that.
Your existing code is appending the product and quantity values in two different builders. The above statement appends them in one builder placing them side by side.
Thanks man! Yours worked to, i really appreciate that!
– Allan Jaqueira
Nov 19 '18 at 18:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379822%2fhow-to-split-stringbuilder-or-print-side-by-side%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use html, or you can literally insert new lines.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
sb
.append(listaCompras1.get(i))
.append(" - ")
.append(listaCompras2.get(i))
.append("n");
}
Rather than storing parallel String lists, though, it would be better if you had a single List<Compra>
Man, than you so much!!! It worked!!!
– Allan Jaqueira
Nov 19 '18 at 18:49
add a comment |
You could use html, or you can literally insert new lines.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
sb
.append(listaCompras1.get(i))
.append(" - ")
.append(listaCompras2.get(i))
.append("n");
}
Rather than storing parallel String lists, though, it would be better if you had a single List<Compra>
Man, than you so much!!! It worked!!!
– Allan Jaqueira
Nov 19 '18 at 18:49
add a comment |
You could use html, or you can literally insert new lines.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
sb
.append(listaCompras1.get(i))
.append(" - ")
.append(listaCompras2.get(i))
.append("n");
}
Rather than storing parallel String lists, though, it would be better if you had a single List<Compra>
You could use html, or you can literally insert new lines.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < listaCompras1.size(); i++){
sb
.append(listaCompras1.get(i))
.append(" - ")
.append(listaCompras2.get(i))
.append("n");
}
Rather than storing parallel String lists, though, it would be better if you had a single List<Compra>
answered Nov 19 '18 at 17:39
cricket_007cricket_007
79.6k1142109
79.6k1142109
Man, than you so much!!! It worked!!!
– Allan Jaqueira
Nov 19 '18 at 18:49
add a comment |
Man, than you so much!!! It worked!!!
– Allan Jaqueira
Nov 19 '18 at 18:49
Man, than you so much!!! It worked!!!
– Allan Jaqueira
Nov 19 '18 at 18:49
Man, than you so much!!! It worked!!!
– Allan Jaqueira
Nov 19 '18 at 18:49
add a comment |
Try using the following :
StringJoiner joiner = new StringJoiner("n");
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
String q = listaCompras2.get(i);
joiner.add(p + " - " + q);
}
String result = joiner.toString();
A StringBuilder
could have been used like
sb.append(p).append(" - ").append(q).append("n");
in the loop but would have resulted in an extra newline at the end. The StringJoiner avoids that.
Your existing code is appending the product and quantity values in two different builders. The above statement appends them in one builder placing them side by side.
Thanks man! Yours worked to, i really appreciate that!
– Allan Jaqueira
Nov 19 '18 at 18:50
add a comment |
Try using the following :
StringJoiner joiner = new StringJoiner("n");
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
String q = listaCompras2.get(i);
joiner.add(p + " - " + q);
}
String result = joiner.toString();
A StringBuilder
could have been used like
sb.append(p).append(" - ").append(q).append("n");
in the loop but would have resulted in an extra newline at the end. The StringJoiner avoids that.
Your existing code is appending the product and quantity values in two different builders. The above statement appends them in one builder placing them side by side.
Thanks man! Yours worked to, i really appreciate that!
– Allan Jaqueira
Nov 19 '18 at 18:50
add a comment |
Try using the following :
StringJoiner joiner = new StringJoiner("n");
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
String q = listaCompras2.get(i);
joiner.add(p + " - " + q);
}
String result = joiner.toString();
A StringBuilder
could have been used like
sb.append(p).append(" - ").append(q).append("n");
in the loop but would have resulted in an extra newline at the end. The StringJoiner avoids that.
Your existing code is appending the product and quantity values in two different builders. The above statement appends them in one builder placing them side by side.
Try using the following :
StringJoiner joiner = new StringJoiner("n");
for (int i = 0; i < listaCompras1.size(); i++){
String p = listaCompras1.get(i);
String q = listaCompras2.get(i);
joiner.add(p + " - " + q);
}
String result = joiner.toString();
A StringBuilder
could have been used like
sb.append(p).append(" - ").append(q).append("n");
in the loop but would have resulted in an extra newline at the end. The StringJoiner avoids that.
Your existing code is appending the product and quantity values in two different builders. The above statement appends them in one builder placing them side by side.
answered Nov 19 '18 at 17:49
PranjalPranjal
1363
1363
Thanks man! Yours worked to, i really appreciate that!
– Allan Jaqueira
Nov 19 '18 at 18:50
add a comment |
Thanks man! Yours worked to, i really appreciate that!
– Allan Jaqueira
Nov 19 '18 at 18:50
Thanks man! Yours worked to, i really appreciate that!
– Allan Jaqueira
Nov 19 '18 at 18:50
Thanks man! Yours worked to, i really appreciate that!
– Allan Jaqueira
Nov 19 '18 at 18:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379822%2fhow-to-split-stringbuilder-or-print-side-by-side%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
this wont work, whatsapp and other apps are going to break the lines the way they want... you didn't inject enough spaces to make over the differents product names length... whatsapp and major app fonts are not shell type, it means different letters have different sizes and it wont ever print the way you put on example
– Rafael Lima
Nov 19 '18 at 17:53
when making a propper question fill enough information to people help you, nobody will guess what
lisaCompras
is– Rafael Lima
Nov 19 '18 at 17:54