I am using a text file that stores 3 columns of data, each having varying length.
This is the following code I have tried so far. I want each column to be left justified. For some reason it works if I use an asterisk and not if I try to manually insert a whitespace.
(line is reading in 3 words from my text file)
Attempt #2:
while((line = buf.readLine())!= null){
StringTokenizer st = new StringTokenizer(line);
int length = 12;
a = st.nextToken();
while (a.length() <= length)
{
a = a + "*";
}
b = st.nextToken();
while (b.length() <= length)
{
b = b + "*";
}
c = st.nextToken();
text.append(a + b + c + '\n');
}
This was my original attempt but this did not work either:
text.append(String.format(“%-15s\t %-10s\t %-5s\t \n”, a, b, c));
Any ideas would be greatly appreciated.
The key here is not to use just a single TextView for your three columns. You want to use a different TextView for each column and the control the formatting of each TextView individually. What type of layout are you using? If you switch to a table layout, it should be easy to left justify what ever you want. If your file will have a variable length, use a ListView which has three different text views in each row and then left justify each textview.