Reputation: 31
I need to put String tab in textview
. how to do it with android Text view
textview1.setText("ABC - answer");
textview2.setText("ABSDE - answer");
textview3.setText("SOMETEXT - answer");
//Required out put
ABC - answer
ABSDE - answer
SOMETEXT - answer
Upvotes: 2
Views: 2355
Reputation: 1469
If you are displaying the text in a fixed-width font, there are ways to pad Strings with spaces. You can use Apache Commons Lang StringUtils for that. It has leftPad
and rightPad
methods.
Another option is by using String.format()
. For example:
System.out.println(String.format("%-10s - %s", "ABC", "answer"));
System.out.println(String.format("%-10s - %s", "ABCDE", "answer"));
System.out.println(String.format("%-10s - %s", "SOMETEXT", "answer"));
Produces:
ABC - answer
ABCDE - answer
SOMETEXT - answer
See Java Format String syntax.
Upvotes: 5
Reputation: 31
Do this
textview.setText(String.format("%s \t - %s", "ABC ", " answer"));
Upvotes: 0