Arabic Text displaying Problems - android

I am getting the problem while displaying arabic text in my android device
the require text is shown below
i am getting the different text like this
I am using the following code for this
my text is this :
category_arabic[3] = "محـامـون" ;
Typeface tfarsi1 = Farsi.GetFarsiFont(this);
((TextView) pageView
.findViewById(R.id.menu_txtAttorneyLegalServices_ar))
.setTypeface(tfarsi1 );
((TextView) pageView
.findViewById(R.id.menu_txtAutoRepairSmog_ar))
.setText(Farsi.Convert(category_arabic[3]));
Please give me some solution for this problem. what i have to do for this ? i also used the ArabicUtilities.java file for this solution but not get the proper solution

you can use ArabicUtilities.java and reshape your text with "reshaper" function. for example:
textView1.setText(ArabicUtilities.reshape("نمايش"));

Related

Marked text (<b>) from a SQLite database won't get bold

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

u\2022 not displaying in textview that retrieves from json

I had found an answer that we can use bullets in textview by adding u\2022 with the text.
Ref : https://stackoverflow.com/a/3429643/4919237
When i added this code through XML it displays fine in TextView
and When i try to display bullet through json it doesnt display bullet ,instead it displays the text u\2022 itself.
my receiving Json format is
{"description":"\\u2022first one\\n\\u2022second one edited\\n"}
please help me to reslove my problem.
At First , You can check Html.fromHtml & remove one \ .
Html.formHtml method takes an Html.TagHandler and an Html.ImageGetter
as arguments as well as the text to parse.
YourTextViewObj.setText(Html.fromHtml("Your String"));
FYI
Currently android seems support the following HTML tags to be rendered on TextView.
You can set text using Html.fromHtml like
textview.setText(Html.fromHtml(your description));

Hide only part of text in TextView

Good Day i want to hide some specified or certain part of text in textview!Important: Im not talking about hide the full textview with TextView.setVisibility(View.Gone) I'm not talking about transparent of TEXT in textview!im not talking about hiding full text in textview!So please help me to hide some text.
Example: lets say i have a textview with this text (10-Sporting Goods)
I want to hide the (10-) and show only Sporting Goods text.Any help will be appreciated!Thank you very much beforehand!
Although even i would appreciate for your case to strongly go with DroidWorm/Gabriella approach , just for the information of all the other folks who may see this in future.
If you really wish to hide just a portion of your textview which has the entire string in itself, you should use a SpannableString , as below:-
tvHello = (TextView) findViewById(R.id.tvHello);
SpannableString customText = new SpannableString("10-Sporting Good");
customText.setSpan(new RelativeSizeSpan(.1f), 0, 3, 0);
tvHello.setText(customText);
This code will technically HIDE the 10- from 10-Sporting Good without using a substring.
You could try to get the whole text like
String text = textView.getText().toString();
and then make substring of it like this:
String wantedSubstr = text.substring(4); //for example - everything from the 4th index to the end
then set this substring as text of your textView like this:
textView.setText(wantedSubstr);
There is one the possible solution of it is that..First you have to find the index(position) of "-" and than split the string according to it therefore use below code
String text = textView.getText().toString();
int position=text.indexOf('-');
String wantedSubstr = text.substring(position+1);
textView.setText(wantedSubstr);
Will there always been "10_" in front of it? Or will there always be 3 characters before the text you want? Or will there always be a "-" or "_" before the text you want?
If so, you could just do a simple method which takes the substring and then updates the textview. If so I can help you write a simple method
You cannot hide part of textView, instead you can make a substring of the specific string and setText using it.
Do it like:
String originalString = "10-Sporting Goods";
String subString = originalString.substring(3);
textView.setText(asubstring);

How to change color of a text using HTML tag in Android

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:

Change Layout Of Text Created In Java [Android]

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();

Categories

Resources