0

i'm writing a chat application, and to parse emotion icons i use code from here Displaying emoticons in Android

my chat text is stored like "SENDER|TIME|NON_PARSED_CHAT_TEXT" in an ArrayList

the problem is that i have all chat messages (time and sender and chat text) in a single string, and i split it and display it in a row in a ListView, each time i get this chat text and re-parse it for the emotion icons, is there any possible way to store Spannable object (chat text after parsing resulted from the function in the question provided) to string in an ArrayList with the time and sender?

thanks

Community
  • 1
  • 1
killercode
  • 1,666
  • 5
  • 29
  • 42
  • I am doing something similar HERE!!! http://stackoverflow.com/questions/16768930/implementations-of-emoji-emoticon-view-keyboard-layouts – Etienne Lawlor May 27 '13 at 17:11

1 Answers1

2

is there any possible way to store Spannable object (chat text after parsing resulted from the function in the question provided) to string in an ArrayList with the time and sender?

You are welcome to use toHtml() on the Html class, though that can only handle some HTML output, not arbitrary things.

You could also have an ArrayList that holds the Spannable rather than a String conversion of that Spannable.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • wont the toHtml() do the same thing? search text for tag and replace it everytime? same as Spannable? – killercode Feb 15 '13 at 18:01
  • @killercode: `toHtml()` takes a `Spannable` and generates HTML. You are thinking of `fromHtml()`, which takes HTML and generates a `Spannable`. – CommonsWare Feb 15 '13 at 18:02
  • so, you mean i should parse the emotion icons like usual, use Html.toHtml() and then store result as string? i'm going to try that now – killercode Feb 15 '13 at 18:05
  • @killercode: To be honest, I am completely lost as to what you are trying to do overall. You asked how to "store Spannable object... to string", which is what I am trying to answer. – CommonsWare Feb 15 '13 at 18:07
  • yes, store Spannable to string while keeping it's parsed state, so next time i want to load the chat text from the array list, it displays it directly, without the need or re-parsing String to Spannable again, i tried Html.toHtml, it displays "

    "
    – killercode Feb 15 '13 at 18:14
  • @killercode: "store Spannable to string while keeping it's parsed state" -- by definition, that is not possible. That's like saying "I want to store a float to string while keeping it as a float" or "I want to store a Restaurant to string while keeping its parsed state". – CommonsWare Feb 15 '13 at 18:15
  • so the only option is to use ArrayList ? – killercode Feb 15 '13 at 18:15
  • @killercode: "so the only option is to use ArrayList ?" -- I can't speak for the `ArrayList` part, but the most straightforward way to keep a `Spannable` would be to keep a `Spannable`. – CommonsWare Feb 15 '13 at 18:16