If a TextView has a georgian text, I see only spaces.
i.e
String georgString = "("+"სახლი ქუჩის ბოლოში"+")";
I see:
"( )"
If a TextView has a georgian text, I see only spaces.
I found quick solution. You need to add your gregorian text into strings.xml and then it will work.
<string name="test">(სახლი ქუჩის ბოლოში)</string>
// an usage
textView.setText(getString(R.string.test));
(I just tested it and it works. Probably if you are assigning text directly there is problem with encoding but with an usage of resources you don't have to deal with it). Let me know.
Related
I have an issue when mixing in one string English, Hebrew and digits.
The order of digits next to Hebrew is getting reversed, no matter what order I make - fist digit and then text, of first text and then Hebrew - it's getting reversed to: on the left digit, on the right text.
My text example is:
String leftPart = "10 gr";
int numder = 8;
String hebrewText = "כפות";
String rightPart = hebrewText + " " + number;
String finalString = leftPart + " · " + rightPart; //10 gr · כפות 8
I want to display the digit 8 in the end of this string, after the Hebrew word, not before it, but I'm unable to do it even here...it's getting reversed because of the English text in the begging.
Even if I change the order to:
String rightPart = number + " " + hebrewText ;
the result is the same...
Any ideas? It's looks like something simple that I'm missing
A tip for forcing English to be shown nicely when mixed with Hebrew:
Wrap the English (or numbers) words with LRI and PDI (check here: https://unicode.org/reports/tr9/ ) .
For example, instead of these (first word is in English) :
<string name="test">ABC היא האפליקציה הכי טובה</string>
<string name="test2">%1$s היא האפליקציה הכי טובה</string>
Use these:
<string name="test">\u2066ABC\u2069 היא האפליקציה הכי טובה</string>
<string name="test2">\u2066%1$s\u2069 היא האפליקציה הכי טובה</string>
Other useful ones can be found here:
https://stackoverflow.com/a/10989502/878126
Nothing is screwing up here, this is actually correct behavior. The number is coming after the end of the hebrew word- the end of the hebrew word is on the left. What you seem to want is for the number to come before the hebrew word. But when you combine it with english like that it doesn't know tht the number is supposed to be bound to the hebrew part and not the english part, so putting it before the hebrew doesn't work either.
I'd suggest putting the number before the hebrew part and wrapping the number and hebrew text in unicode right to left mark characters, to tell it explicitly the 8 is part of the right to left text.
Alternatively you could put the number after the hebrew text but use an rtl mark before the hebrew and a ltr mark after. Which is probably a slightly better way of doing things overall if you want more complex embedding elsewhere.
i followed the answers of some questions here related to getting bold a specific part of text from an external sqlite database. i found a solution which require to add tags before and after the desired text ..adding them and adding Html.fromHtml in java file didn't change nothing ..thanks to correct me or show me a better method. ( and if you know how to change color, that would be great), PS: i have already made some research but wasn't lucky!
This is my code:
TextView groupName = (TextView) view;
String groupname;
groupname = cursor.getString(cursor.getColumnIndex(Database.DATABASE_GROUP_1));
groupName.setText(Html.fromHtml(groupname));
this is a picture from the emulator showing the tags in text(UPDATED):
blob:https://imgur.com/aab1bc1c-4645-4124-8a68-97a949d5c227
EDIT1:
I've changed the text to <b> or limen nasi </b> but still no luck!
You missed the enclosing tag </b> at your example you have two opening tags <b> the second one should be closing.
Note that the following works:
groupName.setText(Html.fromHtml("aaa, <b> o mmm </b> smm"));
Android supports some HTML tags, to change text color there's also <font color:#010203>text</font>
Check if you returning correctly the value from SQLite
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"
how to bold a part of text Android String and in parallel use Message format?
I can do the part of the text bold only if the text is fixed,
but I want to use also in Message.format in order to set custom text.
something like that:
hello <b>{0}</b>, my name is <b>{1}</b>, my age is <b>{2}</b>....
hello world, my name is Josh, my age is seven
try Html.fromHtml() function on text like below
textView.setText("hello"+Html.fromHtml("<b>{0}</b>")+", my name is"+Html.fromHtml("<b>{1}</b>"));
Just build your String in HTML and set it:
String array[]={"World","Josh","Seven"};
String sourceString = "hello <b>"+array[0]+"</b>, my name is <b>"+array[1]+"</b>, my age is <b>"+array[2]+"</b>";
mytextview.setText(Html.fromHtml(sourceString));
OP: hello world, my name is Josh, my age is seven
Ok right , i asked how to create a random number from 1-100 for android and i came to this
TextView tv = new TextView(this);
int random = (int)Math.ceil(Math.random()*101);
tv.setText("Your Number Is..."+ random );
What this does is create the default kinda "hello world" style text view and says "Your Number Is.... [Then Random Number]
My problem is that i cant change the layout of this text , because it is not defined in XML, if someone could tell me how to change the style , or like make the random number into a string so i could use it for any Textview layout that would be great ..
Thanks :)
If by change the style you mean the text color, text size, and you want to change them programmatically, have a look at the setTextColor and setTextSize methods.
More info here
If you want more advanced formatting to set programmatically, see this link.
The below example demonstrates how to make your text bold and italic.
tv.setText("Your Number Is..."+ random, TextView.BufferType.SPANNABLE );
Spannable myText = (Spannable) tv.getText();
myText.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),0,myText.length(),0);
Edit:
Try the below for the android:textSize="100dp" and android:gravity="center" :
tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 100);
tv.setGravity(Gravity.CENTER);
Putting it into a string is easy.
String randomAsAString = Integer.toString(random)
You can then use the XML properties of the TextView to change its formatting, such as android:textSize="30dp" or android:textColor="#900".
By the way, if you're happy with the answer to your previous question, you should go back and mark an answer as "Accepted". That gives 'reputation' points to the person whose answer you accepted and closes the question so that people don't think you're still waiting for a better answer. You can read more about reputation in the FAQ.
Edit:
You can't reference the string entirely in xml while still giving it a random number. This is because the "#string/some_string" format only allows unchangeable strings. The execption to this is using parameters, e.g. setting the string as
<string name="random_number">The random number is %d</string>
Then you could call up that string using something like
yourTextView.setText(this.getString(R.string.random_number, random))
As for your other question about setting a background to a textView, that's also easy.
yourTextView.setBackgroundDrawable(R.drawable.....)
You should take advantage of Eclipse's autocomplete feature... it makes finding these commands a lot easier. For example, simply type the name of your TextView followed by a period, pause half a second for the list of options to come up, then "setB" and it should then filter the list to the three setBackground Drawable/Resource/Color options.
tv.setText(Html.fromHtml("Your number is: <b>" + random + "</b>"));
For basic HTML text-styling tags.
You could also do something like this.
Define your string in strings.xml like:
<string name="your_number_is">Your number is <xliff:g id="number">%s</xliff:g>.</string>
Create a TextView in a layout xml:
<TextView android:id="#+id/your_number_is"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/your_number_is"
android:gravity="center"
android:textSize="100dip"
/>
Then your code would look like:
TextView tv = (TextView) findViewById(R.id.your_number_is);
int random = (int)Math.ceil(Math.random()*101);
tv.setText(getString(R.string.your_number_is, random));
This will make it a lot easier when you later on would like to change your text or maybe localize your app.
if you have thead troubles use this:
new Thread(){
public void run(){
TextView v = (TextView)findViewById(R.id.mytext);
v.setText("TEST");
}
}.start();