Arabic text appearing reverse when Arabic text comes with digit - android

I need to print the below string which is in Arabic on TextView in Android. It is printing good but when the Arabic text and digits falls in a same string, Android put the digit at end!
here is my code
String str = "مقر 44";
TextView textView = (TextView)findViewById(R.id.test);
textView.setText(str);
Here is the output

you can try with this workaround
String str = "44 "+"مقر ";
TextView textView = (TextView)findViewById(R.id.txt_title);
textView.setText(str);
its not Android who put digit at the end, its because of Arabic writing standard

Related

How to fade some character of a textview?

I have a Textview with some texts. So if the line count is more than two i have to fade some characters at the end of second line.
How can we do something like that?
You can use html font color like that :
String text = textView.getText().toString();
String a = text.substring(0, text.length()-2);
String b = text.substring(text.length()-2, text.length()-1);
String c = text.substring(text.length()-1, text.length());
text = "<font color=#000000>"+a+"</font><font color=#777777>"+b+"</font>"+"<font color=#AAAAAA>"+c+"</font>";
textView.setText(Html.fromHtml(text));
Result screenshot :

Put emoji code in a string

I am using this emoji library
https://github.com/hani-momanii/SuperNova-Emoji
This library has a custom textview which can render emojis. How do I set text of that textview so it displays emojis ?
For example I tried this and it did not work :
String happy = " Feeling happy U+1F601 ";
emojitextview.setText(happy);
Switch out the 'U+' for '0x':
int unicode = 0x1F601;
String happy = "Feeling happy " + getEmojiByUnicode(unicode);
And put it through a helper function:
public String getEmojiByUnicode(int unicode){
return new String(Character.toChars(unicode));
}
p.s. if it still doesn't work, you may have to set the textView to use a typeface that supports emoji characters
from:
how set emoji by unicode in android textview

Unicode to text in java

How can I convert a Unicode string like
"\u0646\u0627\u0645"
to a human-readable string that I can put in a TextView?
No need to do anything more than this
TextView text = (TextView) findViewById(R.id.yourTextView);
text.setText("\u0646\u0627\u0645");

How do I update a text edit in Android Studio

Basically, I need to know how to insert a user inputted string into a text edit on my gui from within my code.
Try this-
String str = "this is a text";
EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setText(str, TextView.BufferType.EDITABLE);
You can use any string in String object.

Format currency dynamically on TextView

I'm trying to dynamically format the value entered by the user on a TextView, specifically what I am trying to do is:
1. TextView text = ""
2. User entered = "4"
3. TextView text = 0.04
4. User entered = "5"
5. TextView text = 0.45
6. User entered = "6"
7. TextView text = 4.56
and so on...
I'm using the onTextChangedmethod stub from TextWatcher, although I don't know how to implement this logic.
What is the simplest way to implement this feature?
You have to use NumberFormat in this case, e.g:
double moneyCurrency = 100.1;
NumberFormat baseFormat = NumberFormat.getCurrencyInstance();
String moneyString = baseFormat.format(moneyCurrency);

Categories

Resources