0

I'm getting long description text from the api like this

  {"status":true,"data":[{"id":674,"product_category_id":1,"child_category_id":1,"child_category_two_id":null,"child_category_three_id":null,"supplier_id":2,"supplier_name":"\u0627\u0644\u0645\u062f\u064a\u0631 \u0627\u0644\u0639\u0627\u0645","option_category_id":null,"tax_id":1,"barcode":0,"low_price":114,"image":"1586519373.jpeg","cost":115,"name_ar":"\u0633\u0644\u0629 \u0627\u0645\u0633\u0648 \u0627\u0644\u063a\u0630\u0627\u0626\u064a\u0629","name_en":"Amso food basket","details_ar":"\u0648\u0627\u062d\u062f \u0643\u064a\u0633 \u0623\u0631\u0632 \u0623\u0628\u0648 \u0643\u0627\u0633  \u062e\u0645\u0633\u0629 \u0643\u064a\u0644\u0648\r\n\u0648\u0627\u062d\u062f \u062d\u0644\u064a\u0628 \u0628\u0648\u062f\u0631\u0629 \u0627\u0644\u0641 \u0648\u062b\u0645\u0627\u0646\u0645\u0627\u0626\u0629 \u062c\u0631\u0627\u0645\r\n\u0648\u0627\u062f \u0632\u064a\u062a \u0627\u0644\u0641 \u0648\u0633\u062a\u0645\u0627\u0626\u0629 \u062c\u0645\r\n\u0648\u0627\u062d\u062f \u0634\u0639\u064a\u0631\u064a\u0629 \u0627\u0631\u0628\u0639\u0645\u0627\u0626\u0629 \u0648\u062e\u0645\u0633\u0648\u0646 \u062c\u0645\r\n\u0648\u0627\u062d\u062f \u0645\u0639\u062c\u0648\u0646 \u0637\u0645\u0627\u0637\u0645 \u062b\u0645\u0627\u0646\u0645\u0626\u0629 \u0648\u0639\u0634\u0631 \u062c\u0645\r\n\u062b\u0644\u0627\u062b \u0639\u0644\u0628 \u0641\u0648\u0644 \u0645\u062f\u0645\u0633 \u0627\u0644\u0641 \u0648\u0645\u0627\u0626\u062a\u064a\u0646 \u062c\u0645\r\n\u062b\u0644\u0627\u062b \u0639\u0644\u0628 \u062a\u0648\u0646\u0629 \u062e\u0645\u0633\u0645\u0627\u0626\u0629 \u0648\u062e\u0645\u0633\u0648\u0646 \u062c\u0645\r\n\u0648\u0627\u062d\u062f \u0633\u0643\u0631 \u0627\u062b\u0646\u064a\u0646 \u0643\u064a\u0644\u0648\r\n\u0627\u062b\u0646\u064a\u0646 \u0645\u0639\u0643\u0631\u0648\u0646\u0629 \u0645\u062a\u0646\u0648\u0639\u0647 \u0627\u0644\u0641 \u062c\u0645","details_en":"one Abu kas rice five kg   one powdered milk on thousand and eight hundred gm one vegetable oil on thousand and six hundred gm one fine noodles four hundred fifty gm  one tomato paste eight hundred and ten gm three beans cans   three tuna cans  one sugar two Kg two  mixed pasta one kg","sumInv":500,"campaign":{"id":null,"product_id":null,"price":null,"purchasesLimits":null,"stock":null},"packages":[{"package_id":2436,"package_price":"114.2900","unit_count":1,"existing":0,"virtual":500}]}],"last_page":1,"current_page":1,"per_page":16}

, but the problen when I displayed in textview I got this weird result

enter image description here enter image description here

As it appears it looks different in Arabic and English, in Arabic the spaces almost between every word but in english it happens in line 1,2 and 3 before some words.

here is the code on the textview which container is a constraintlayout

<TextView
            android:id="@+id/tv_activity_detail_description"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingStart="8dp"
            android:paddingEnd="8dp"
            android:paddingBottom="4dp"
            android:paddingTop="4dp"
            android:textSize="12dp"
            android:textColor="@color/colorDarkGray"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cardView" />
  • At first, I was like this looks like a good recipe. Then I got to beans and tuna and suddenly lost my appetite. – Elliott Frisch Apr 10 '20 at 22:29
  • please try to put each language text in a different `TextView` – Zain Apr 10 '20 at 22:39
  • @Zain I will do it but what's the reason of this , why words displayed like that –  Apr 10 '20 at 23:11
  • I guess it may need different language may need different local that may be auto handled by another TextView – Zain Apr 10 '20 at 23:14
  • @ElliottFrisch It wasn't real a recipe it's a help bag with some necessary food which given to people who needs, anyway you can make a great salad with tuna and beans try it :) –  Apr 10 '20 at 23:15
  • the weird is this textview works fine with other descriptions it just be like that with this description only @Zain –  Apr 10 '20 at 23:17
  • 1
    Please let me know what is wrong when you solve it :) – Zain Apr 10 '20 at 23:59
  • 1
    @Zain sure I will –  Apr 11 '20 at 00:15
  • @Zain check my answer I solved it , thanks for help anyway –  Apr 11 '20 at 00:58
  • 1
    great well done – Zain Apr 11 '20 at 01:07

1 Answers1

1

I found the problem with the unicode characters so when I tried to display the text using it's unicode characters it gives me the current screen but I get the real text of this Unicode and it displayed fine, anyway I find the solution by using the text as HTML in java:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        textView.setText(Html.fromHtml(user.getInput(), Html.FROM_HTML_MODE_LEGACY));
    } else {
        textView.setText(Html.fromHtml(user.getInput()));
    }

I got the solution from this answer