0

I have a rich textview (I don't know the exact name of it but it shown in the image below) in admin control panel that allow the admin to write the description of product Html Dialog

and I have an api that return the code of this textbox and it return something like this for the above text:

<ul><li>Simple product with user role price activited</li><li>Without flavor and size<br></li></ul>

My question is how can I display this kind of rich text view code into text view in my apk

Edit: I tried to use fromHtml method but it doesn't work, maybe because I have html tags like ul and li?

Ali Habbash
  • 777
  • 2
  • 6
  • 29

1 Answers1

3

You can use WebView to display your HTML data like this

val webView = findViewById<WebView>(R.id.my_webview)
val text = "<ul><li>Simple product with user role price activited</li><li>Without flavor and size<br></li></ul>"
webView.loadDataWithBaseURL(null, text, "text/html", "utf-8", null)
Vladimír Bielený
  • 2,795
  • 2
  • 11
  • 16
  • That saved my day, thanks. Another question Java does not allow the long strings to be stored directlly but in my case, the text is stored in String variable which get its value from API and when the string is too long an error will be thrown or not in that case? – Ali Habbash Jun 13 '18 at 21:20
  • I don't think that should be a problem, String can have up to 2^31-1 characters. Only limitation is with compile time string. – Vladimír Bielený Jun 14 '18 at 02:38