Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>What is the purpose of these interfaces?</p> </blockquote> <p><a href="http://yuml.me/5f8da6cb"><img src="https://i.stack.imgur.com/DeELW.png" alt="diagram from yuml.me/edit/5f8da6cb"></a> <code>CharSequence</code> is a standard Java interface representing a sequence of characters. <code>String</code> is the most commonly-used concrete implementation of <code>CharSequence</code>, followed by <code>StringBuilder</code>.</p> <p><code>Spanned</code> is a <code>CharSequence</code> with "spans" indicating formatting to apply to portions of the text, where those spans cannot be modified.</p> <p><code>Spannable</code> is a <code>Spanned</code>, adding in the ability to modify the spans (to add or remove formatting), but <em>not</em> to modify the text itself.</p> <p><code>SpannedString</code> is a concrete implementation of the <code>Spanned</code> interface.</p> <p><code>SpannableString</code> is a concrete implementation of the <code>Spannable</code> interface.</p> <blockquote> <p>in which scenarios is it mostly common to use them?</p> </blockquote> <p>When there is a method that returns one (e.g., <code>getText()</code> on an <code>EditText</code>) or when there is a method that takes one as a parameter (e.g., <code>setText()</code> on a <code>TextView</code>). <a href="http://yuml.me/35c8f39f"><img src="https://i.stack.imgur.com/S9rZN.png" alt="diagram from yuml.me/edit/35c8f39f"></a></p> <p>Your cited case of using <code>Html.fromHtml()</code> is perhaps the most common in conventional Android development, as a <code>TextView</code> with a <code>Spanned</code> is much lighter in weight than is a <code>WebView</code>. However, there are other use cases, such as:</p> <ul> <li><p><a href="https://github.com/commonsguy/cw-omnibus/tree/master/RichText/Search">Highlighting search results</a></p></li> <li><p>Allowing users to <a href="https://github.com/commonsguy/cwac-richedit">enter in rich text</a>, then using <code>Html.toHtml()</code> to persist that formatted text in an HTML rendition</p></li> </ul> <blockquote> <p>In which cases is it best to avoid using them?</p> </blockquote> <p>They are singularly awful at combating baldness, snow removal, heat pump repair, making a soufflé, etc.</p> <p>:-)</p> <blockquote> <p>Are there any obvious performance impacts to be considered when using any one of them?</p> </blockquote> <p>Interfaces, by definition, do not have "performance impacts" -- they are merely a description of an API.</p> <p>I am not aware that <code>SpannableString</code> is significantly slower than <code>SpannedString</code> at any particular operation. However, <code>SpannableStringBuilder</code> (which allows for manipulating the text in addition to the spans that format that text) may well be a bit slower than <code>SpannableString</code> or <code>SpannedString</code> for various things. Whether or not the performance differences are enough to matter will depend on usage, though.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload