Abhinay Bali
Abhinay Bali

Reputation: 1

In android, I have Edittext view containing Spannable text

In Android, I have an Edittext view containing Spannable text including images in that. when I convert it to HTML using "toHTML" I am getting image source as a null. Anybody help me how to get the name of image in place of null.

example i have content like "abhi"[Some image]

when I convert it I am getting HTML as below.

<p dir="ltr"><img src="null">&nbsp; <u>abhi</u></p>  

Instead of that i want

<p dir="ltr"><img src="imagename">&nbsp; <u>abhi</u></p>  

Upvotes: 0

Views: 281

Answers (2)

cmoaciopm
cmoaciopm

Reputation: 2256

It depends on how the spanned text is constructed. Suppose the image contained in the spanned text is an ImageSpan instance.

ImageSpan has many constructors:

  • ImageSpan(Drawable d, String source)
  • ImageSpan(Drawable d, String source, int verticalAlignment)
  • ImageSpan(Context context, Uri uri)
  • ImageSpan(Context context, Uri uri, int verticalAlignment)

Those constructors will assign a value to mSource(an internal member of ImageSpan), which will be later used by Html.toHtml() to generate a valid src.

Other commonly used constructor of ImageSpan:

  • ImageSpan(Bitmap b)
  • ImageSpan(Context context, Bitmap b)
  • ImageSpan(Drawable d)

When image in spanned text is created using above constructors, you will get null as src.

Upvotes: 1

Sayan Manna
Sayan Manna

Reputation: 679

String htmlString = Html.toHtml(SpannableText);

Upvotes: 0

Related Questions