Reputation: 219
i have a text file, that i want to display it's text in the number of text views,that i set their texts in run time.
here is my code, that i use for my program:
while(text.length() > 0)
{
text = text.trim();
int index = text.indexOf("L1");
int index2 = 0;
temp = "";
if(index > -1 && index == 0)
{
index2 = text.indexOf("/L1");
temp = text.substring(index + 2, index2);
temp.trim();
t = temp.toCharArray();
text = text.substring(index2 + 3, text.length());
index = text.indexOf("\r\n");
while(index > -1 && index == 0)
{
temp += "\r\n";
text = text.substring(index + 2, text.length());
index = text.indexOf("\r\n");
}
temp = String.valueOf(t);
}
else
{
index = text.indexOf("L2");
if(index > -1 && index == 0)
{
index2 = text.indexOf("/L2");
temp = text.substring(index + 2, index2);
text = text.substring(index2 + 3, text.length());
index = text.indexOf("\r\n");
while(index > -1 && index == 0)
{
temp += "\r\n";
text = text.substring(index + 2, text.length());
index = text.indexOf("\r\n");
}
}
else
{
index = text.indexOf("List");
if(index > -1 && index == 0)
{
index2 = text.indexOf("/List");
temp = text.substring(index + 4, index2);
text = text.substring(index2 + 5, text.length());
index = text.indexOf("\r\n");
while(index > -1 && index == 0)
{
temp += "\r\n";
text = text.substring(index + 2, text.length());
index = text.indexOf("\r\n");
}
}
else
{
text = text.trim();
index = text.indexOf("Plain");
if(index > -1 && index == 0)
{
index2 = text.indexOf("/Plain");
temp = text.substring(index + 5, index2);
text = text.substring(index2 + 6, text.length());
index = text.indexOf("\r\n");
while(index > -1 && index == 0)
{
temp += "\r\n";
text = text.substring(index + 2, text.length());
index = text.indexOf("\r\n");
}
}
}
}
}
}
for(int i = 0; i < texts.length; i++)
{
TextView tv = new TextView(this);
tv.setText(Farsi.Convert(texts[i]));
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/naz.ttf");
tv.setTypeface(font);
tv.setTextColor(Color.BLACK);
tv.setGravity(Gravity.RIGHT);
tv.setPadding(10, 10, 10, 10);
tv.setLayoutParams(params);
linearLayout.addView(tv);
}
layout.addView(linearLayout);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
this.addContentView(layout, p);
}
i use some auxiliary words(such as "L1" and "/L1") for some reasons in text file, that delete them in run time. but, when i run the program, in the output the text that shown in text views, is not in right style, i want to align it to right, but in the output there are some additional text, that aren't in the input text file.
in the 2 images in below, i attach the output with and without the auxiliary words in the input text file.
output with auxiliary words:
output without auxiliary words, in this state, i set the content of layout using, "setContentView" function, and read the whole file instead of split text using auxiliary words index. in this state, the input does not contain the auxiliary words.
what is the problem friends? thanks
Upvotes: 0
Views: 149
Reputation: 1934
First of all:
use String.split()
to split your string.
It works like this, if you have a string A,B,C and you use myString.split(,)
output will be an array of substrings i.e [A,B,C].
But this is useful in your case if you can have the same delimiter ie L1 and L2 will be same.
Second: You can use android:gravity="right"
in the textview
of your layout.xml
. This will resolve the issue of strings being aligned to left.
Upvotes: 1