My string looks like this "تغطية مباشرة.. ريال مدريد 2-0 مانشستر يونايتد", When I setText in a textview the numbers are getting reversed i.e(0-2 becomes 2-0).
I have tried setting text direction but it wasn't helpful.
Any ideas how to avoid the reversal?
Add this line in your activity onCreate method :
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
Related
Numbers inside TextView are getting reversed when formatted in RTL.
When numbers are at the end of a text inside a TextView they getting reversed. How can I solve this programmatically?
As an example, the numbers below are reversed:
They should be displayed like:
The misunderstand:
Digits in RTL languages like ARABIC should be written from RTL with the arabic digits to avoid any problems i.e: "تم إرسال رسالة نصية للرقم ١٢٣٤" Note that I wrote "رسالة نصية" NOT "SMS رسالة".
The problem and it's solution:
Mixing more than one direction languages required more steps, you need to tell the system "hey this is RTL word, add as it to sequence".
So you may need to do this implicitly, i.e:
\u200f + تم إرسال رسالة نصية إلى + number
Consider StringBuilder: It's very painful for developer to develop something for RTL language using plus(+) notation, this much confusing and error prone.
A better way:
builder.append("\u061C").append(" تم إرسال رسالة نصية لـ").append("\u200E").append("+0123456789")
Consider BidiFormatter: Utility class for formatting text for display in a potentially opposite-directionality context without garbling
Example:
String text = "{0} تم إرسال رسالة نصية لـ ";
String phone = BidiFormatter.getInstance().unicodeWrap("+961 01 234 567");
String result = MessageFormat.format(text,phone);
Now, result will be formatted properly.
More examples on how BidiFormatter work.
If you want to prevent the reversing of numbers for TextView when formatted in RTL, just specify android:textDirection="ltr" property for that specific TextView inside XML file. It will display number in the usual order.
Try this out
android:supportsRtl="false" in manifest file
and android:gravity="start" in your layout.
set the textview gravity to start
android:gravity="start"
i've got a database with a field in var_char(2000).
in this field there's text with some new line, like a normal text written:
hello
i am davide
bye
i put this text in a textview but i see the text like a unique line (hello i am davide bye), without newlines.
in iphone it is all normal and i've done nothing particular... but here no.
how can i?
i've tried with replace \n or replace \r\n o other things but without success.
Also with Html.fromHtml()
the singleLine(false) is deprecated, and it doesn't work.
also text doesn't work. it see the newline as a space
Try setting android:singleLine="false" to your textView.
Edit:
If this does not work check whether the string has a new line character using below code
char[] chararray= mString.toCharArray();
for(char temp:chararry){
int value = temp;
System.out.println(value);
}
Decimal value of Newline is either 10 or 13. While space character is 32.
Edit2 : I think TextView does not go to next line for \r which is 13.
So do
mString = mString.replaceAll("\r","\n");
did you try changing the datatype in sqlite?, your varchar to just text? if not, try doing so maybe it'll help
Try to disable the multi-line feature of the text view.
If you created the text view from an XML file, add this attribute to the text view :
<TextView
[...]
android:singleLine="false"
[...] />
If you created the text view programmatically, try to use the following method instead :
TextView myText = [...]
myText.setSingleLine ( false );
I have a string which contain three words. I want to show the three words in same textview but in different line. For this I have used <br> tag. Now I want to show the last word in red color. I tried so many codes but nothing worked for me.
My code snippet is
viewHolder.cutomerinfo.setText(
customerDetail[0]+Html.fromHtml("<br>")+
customerDetail[1]+Html.fromHtml("<br>")+
Html.fromHtml("<font color='#ff0000'>")+
customerDetail[2]+Html.fromHtml("</font>"));
Do like that:
code:
String toshowstring = customerDetail[0]+customerDetail[1]+
"<font color='red'>"+customerDetail[2]+"</font>";
viewHolder.cutomerinfo.setText(Html.fromHtml(toshowstring));
That's all you want.
^-^
//only one Html.fromHtml() method is enough
viewHolder.cutomerinfo.setText(
customerDetail[0]+Html.fromHtml("<br>"+customerDetail[1]+
"<br><font color='#ff0000'>"+
customerDetail[2]+"</font>"));
for Ref:
I am developing the application which consists of AutoCompleteTextView,here is my problem,How I can upper case the letters entering in AutoCompleteTextView.
I Don't want in xml: android:capitalize="characters"
I want to declare in Java code.
You can try like this..In your text watcher in ontextchanged change the text to upper case..and check if the new string in edittext is the old string which you converted to upper case...in order to avoid stackoverflow error..
String upper = mytextview.getText().toString().toUpperCase()
mytextview.setText(upper);
Try this in your code there are some other flags also which you can check and try.
tv.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
I know that if you do something like
myTextView.setText("This is on first line \n This is on second line");
Then it will display properly like this:
This is on first line
This is on second line
When I store that string in a database and then set it to the view it displays as such:
This is on first line \n This is on second line
Here is the line of code I use to extract the string from the database:
factView.setText(factsCursor.getString(MyDBAdapter.FACT_COLUMN));
I simply populate the database from a text file where each line is a new entry into the table so a line would look like this "This is on first line \n This is on second line" and it is stored as text.
Is there a reason that it isn't displaying the \n characters properly? It must be something to do with the string being in the database. Any suggestions?
I found this question Austyn Mahoney's answer is correct but here's a little help:
private String unescape(String description) {
return description.replaceAll("\\\\n", "\\\n");
}
description being the string coming out of your SQLite DB
As Falmarri said in his comment, your string is being escaped when it is put into the database. You could try and unescape the string by calling String s = unescape(stringFromDatabase) before you place it in your TextView.
As a side note, make sure you are using DatabaseUtils.sqlEscapeString() on any kind of data that is from the user or an unknown changeable source when inserting data into the database. This will protect you from errors and SQL Injection.
Try \\n instead of \n. If it throws an exception than use newline keyword in place of \n....newline is one character, ascii 10; it's often entered in a string literal...and will serve your purpose....:)
"This is on first line"||x'0A'||"This is on second line"
The || concatenates strings and the x'0A' is an unescaped newline.
If you're inserting records you'll have to replace every newline with "||x'0A'||" (If your string is double quoted). This may seem clumsy compared to the other asnswers. However if your lines are in separate columns this also works in a select:
SELECT firstline||x'0A'||secondline FROM wherever;
I found this while having the same problem you are: http://www.mail-archive.com/sqlite-users#sqlite.org/msg43557.html
A text area can be in multi line or single line mode. When it is in single line mode newline characters '\n' will be treated as spaces. When in doubt, to switch multi line mode on you can use the following code:
setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
I had the problem that the same code did not work on honeycomb and on froyo, which seem to have different defaults. I am now also excluding the flag when I want to force a field to be single lined.
From the Android doc:
public static final int TYPE_TEXT_FLAG_MULTI_LINE Added in API level 3
Flag for TYPE_CLASS_TEXT: multiple lines of text can be entered into
the field. If this flag is not set, the text field will be
constrained to a single line. Constant Value: 131072 (0x00020000)
http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_FLAG_MULTI_LINE
You have to set the flag before you populate the field.