9 Replies - 372 Views - Last Post: 17 January 2018 - 06:38 AM

#1 bezamek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 18

trouble with listview

Posted 16 January 2018 - 03:32 PM

i have some html entries in my database & i want to render them as HTML rather than normal text

below is my java code of that activity i am retrieving data from firebase the content in my database look like this

<a href='google.com' target='_Blank'> Click Here </a>


and i want it to convert & display as normal html

find code here https://pastebin.com/raw/9KdiEEx4

Edit:

i want this
<a href='google.com' target='_Blank'> Click Here </a>


to become this

<a href='google.com' target='_Blank'> Click Here </a>


& get displayed as normal html

my java code is above please help me

Is This A Good Question/Topic? 0
  • +

Replies To: trouble with listview

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3568
  • View blog
  • Posts: 16,265
  • Joined: 20-September 08

Re: trouble with listview

Posted 16 January 2018 - 03:46 PM

So, you unescape it. org.apache.commons.lang3.StringEscapeUtils would do it
Was This Post Helpful? 0
  • +
  • -

#3 bezamek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 18

Re: trouble with listview

Posted 16 January 2018 - 04:39 PM

View Postg00se, on 16 January 2018 - 03:46 PM, said:

So, you unescape it. org.apache.commons.lang3.StringEscapeUtils would do it

ok
bot i a not sure how to implement it
i can add this in gradle

but how to use it ? & decode my string & show it in listview ?

thanks in advance
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3568
  • View blog
  • Posts: 16,265
  • Joined: 20-September 08

Re: trouble with listview

Posted 16 January 2018 - 05:03 PM

Quote

but how to use it ?

Add the library commons-lang3, import the class. The usage is is simple:
https://commons.apac...scapeUtils.html
Was This Post Helpful? 0
  • +
  • -

#5 bezamek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 18

Re: trouble with listview

Posted 17 January 2018 - 02:13 AM

View Postg00se, on 16 January 2018 - 05:03 PM, said:

Quote

but how to use it ?

Add the library commons-lang3, import the class. The usage is is simple:
https://commons.apac...scapeUtils.html

thanks
all my html encoded code is not converted back to symbols

but it is still not rendering as html

all html codes is showing as plain text

i tried
 Html.fromHtml


but it is showing error

Incompatible types found 
'android.txt.spanned', required ' java.lang.String'

Was This Post Helpful? 0
  • +
  • -

#6 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3568
  • View blog
  • Posts: 16,265
  • Joined: 20-September 08

Re: trouble with listview

Posted 17 January 2018 - 03:22 AM

fromHtml is not what you want. I gave you the way to do it
Was This Post Helpful? 0
  • +
  • -

#7 bezamek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 18

Re: trouble with listview

Posted 17 January 2018 - 03:54 AM

i used
       String result = Html.fromHtml(results, Html.FROM_HTML_MODE_LEGACY).toString();


& it did the trick
but none of my links are clickable

i tried
setMovementMethod(LinkMovementMethod.getInstance());


but i am receiving error "cannot resolve method"

View Postg00se, on 17 January 2018 - 03:22 AM, said:

fromHtml is not what you want. I gave you the way to do it


this code just decoded the symbols

 String results = StringEscapeUtils.unescapeHtml4(string);


it is displaying html as text
Was This Post Helpful? 0
  • +
  • -

#8 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3568
  • View blog
  • Posts: 16,265
  • Joined: 20-September 08

Re: trouble with listview

Posted 17 January 2018 - 05:26 AM

Quote

i want this
&lt;a href='google.com' target='_Blank'&gt; Click Here &lt;/a&gt;


to become this

<a href='google.com' target='_Blank'> Click Here </a>


& get displayed as normal html

import org.apache.commons.lang3.StringEscapeUtils;

public class Escaper {
    public static void main(String[] args) {
        String esc = "&lt;a href='google.com' target='_Blank'&gt; Click Here &lt;/a&gt;";
        System.out.println(StringEscapeUtils.unescapeHtml4(esc));
    }
}


Output:
[email protected]:/tmp$ java -cp $C:. Escaper
<a href='google.com' target='_Blank'> Click Here </a>
[email protected]:/tmp$ 


What you're doing with the result is probably where you're going wrong
Was This Post Helpful? 0
  • +
  • -

#9 bezamek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 18

Re: trouble with listview

Posted 17 January 2018 - 05:58 AM

hm......
ok thanks
i fixed my code

but my anchor tag is still not working
when i click on it nothing happen

i tried setMovementMethod(LinkMovementMethod.getInstance());
but i an receiving error as i mentioned above

This post has been edited by andrewsw: 17 January 2018 - 06:16 AM
Reason for edit:: removed previous quote, just use the REPLY button

Was This Post Helpful? 0
  • +
  • -

#10 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3568
  • View blog
  • Posts: 16,265
  • Joined: 20-September 08

Re: trouble with listview

Posted 17 January 2018 - 06:38 AM

I'm afraid i probably can't help there as my Android knowledge is slight
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1