0

I'm trying to display Hebrew and normal text mixed, the text comes from a SQLite database and is displayed in a listview that gets pulled from my database in the Assets folder.

I want to display the following:

‘אנא אנא - Ek is, was, sal wees Wie Ek is, was, sal wees.”

But it gets displayed as:

”.Ek is, was, sal wees Wie Ek is, was, sal wees - אנא אנא‘

When the hebrew text is between other normal text its fine like:

‘He says אנא אנא - I am, was, shall be Who I am, was, shall be.”

The text only gets mixed up when the listview item starts with Hebrew.

I've tried:

‘<\U+200f>אנא אנא<\U+200f> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U200f>אנא אנא<\U200f> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘\U200fאנא אנא\U200f - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘(\U200f)אנא אנא(\U200f) - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U+202b>אנא אנא<\U+202b> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U202b>אנא אנא<\U202b> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘\U202bאנא אנא\U202b - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘(\U202b)אנא אנא(\U202b) - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U+202e>אנא אנא<\U+202e> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘<\U202e>אנא אנא<\U202e> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘\U202eאנא אנא\U202e - Ek is, was, sal wees Wie Ek is, was, sal wees.”

‘(\U202e)אנא אנא(\U202e) - Ek is, was, sal wees Wie Ek is, was, sal wees.”

But everything gets displayed with the codes like: (I dont want to see the codes)

‘<\U+200f>אנא אנא<\U+200f> - Ek is, was, sal wees Wie Ek is, was, sal wees.”

Ive tried android:supportsRtl="true" in the manifest, this only affects the text allignment in my case and not the texts.

FDupie
  • 59
  • 12

5 Answers5

3

The issue is that you're mixing an rtl and an ltr text in the same string. The system looks at the string to be displays and see it starts with hebrew. So it starts it in RTL mode. It then sees english text. So it switches to LTR. THe result is what you see. You need to put in explicit unicode ltr and rtl marks when mixing languages like this to ensure that its treated correctly. See https://en.wikipedia.org/wiki/Left-to-right_mark for info on ltr marks.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Same answer as below: I think it works perfectly for a string, but Im importing data from a database, so when I put the code in front of the text in the DB it displays the result with the code in front of it – FDupie Sep 08 '16 at 17:50
  • Please see my completely edited (more specific) post above – FDupie Sep 13 '16 at 19:52
1

Sooo... This finally worked for me....

textview.setTextDirection(View.TEXT_DIRECTION_LTR);

Please note that my problem was as I said, Im reading data from a database and not displaying strings, so this code forces all data to be read from left to right, if I do not use this line, It picks up the Hebrew characters as RTL text and wants to display the whole result as RTL.

Thanks for all the help though! I had a lot of reading and learned in the process!

FDupie
  • 59
  • 12
0

See the answer here....

Ted Hopp answer

I am using the \u200e for right to left

take your string in string.xml

<string name="Yourstring">\u200e שלום</string>


 TextView text2=(TextView)findViewById(R.id.text2);

 String str= getResources().getString(R.string.Yourstring)+" is the same as hello";
 text2.setText(str);

The result as you want

enter image description here

AS you want if you want for database I am adding some demo with the array data you can do these type work with database value

 String[] str_array={"שלום is the same as hello","שלום is the same as hello","שלום is the same as hello","שלום is the same as hello"};


        TextView text1=(TextView)findViewById(R.id.text1);
        TextView text2=(TextView)findViewById(R.id.text2);
        TextView text3=(TextView)findViewById(R.id.text3);
        TextView text4=(TextView)findViewById(R.id.text4);



        String str="";

        for(int i=0;i<str_array.length;i++)
        {
            if(i==0)
            {

              // before text you want than do this
                text1.setText(str.concat("\u200e")+str_array[i]);
            }
            else if(i==1)
            {
                // add this for end of string

                text2.setText(str_array[i].concat("\u200e"));
            }
            else if(i==2)
            {
           // before text you want than do this
                text3.setText(str.concat("\u200e")+str_array[i]);
            }
            else if(i==3)
            {
           // before text you want than do this
                text4.setText(str.concat("\u200e")+str_array[i]);
            }
        }

The result

enter image description here

Community
  • 1
  • 1
Arjun saini
  • 4,223
  • 3
  • 23
  • 51
  • I think it works perfectly for a string, but Im importing data from a database, so when I put the code in front of the text in the DB it displays the result with the code in front of it – FDupie Sep 08 '16 at 17:48
  • @saini can you please explain how to do it – FDupie Sep 09 '16 at 08:57
  • @FDupie I am doing for you just like take the data from string array here... You can try with your database value like that – Arjun saini Sep 09 '16 at 09:21
  • Like I said, I'm pulling data from an database in my assets folder, I edit the data with SqliteBrowser, so I'm not defining strings to display, there's over 1000 hebrew words that is randomly between other normal texts... Or is there a way to implement your above answer in my db? – FDupie Sep 09 '16 at 14:46
  • Show your sqlite data how you are using where you show than I code on your code – Arjun saini Sep 10 '16 at 02:54
  • Please see my completely edited (more specific) post above – FDupie Sep 13 '16 at 19:52
0

You can set

android:textDirection="locale"

Then, text direction will not be based on text, but on the system language. Then on device which language is rtl it will be also displayed correctly

ref: https://developer.android.com/reference/android/view/View.html#attr_android:textDirection

-1
android:supportsRtl="true"

Means you want Right to Left Support for Arabic ,Hebrew Like Language. which is start with RTL Right to left , when System get that Language is Hebrew,it starts with right.As per my Suggestion you need to define that did you really need RTL support in your app. otherwise please set android:supportsRtl="false" so its start Left to right.

Himeshgiri gosvami
  • 2,559
  • 4
  • 16
  • 28
  • It only affects the text that I set in certain places that started to read from the right side of page to move to the left, this does not affect the data direction – FDupie Sep 08 '16 at 17:11
  • Please see my completely edited (more specific) post above – FDupie Sep 13 '16 at 19:53