Android : How to discard elements with non-breaking space before adding them in an Arraylist

on Tuesday, September 2, 2014


I have an HTML that looks something like this



<div class="copy>
<p>First tip</p>
<p><span style="FONT-SIZE:medium"><br/></span></p>
<p>Second Tip</p>
<p>&nbsp;</p>
<p>Third tip</p>
<p>&nbsp;</p>
<p>Fourth tip</p>
</div>


I'm using Jsoup to extract the text inside the p elements and store them in an arraylist. But I don't want to store the ones that don't have any text in them . I've tried the following but it doesn't work.



Elements tips = doc.select("div.copy > p");
for(Element tip: tips) {
if(tip.text() != "") {
if(tip.text() != "&nbsp;") {
tipsArray.add(tip.text());
}
}

}


The code doesn't add the second p element with the br tag in the arraylist but it isn't working for &nbsp. I'm trying to use the arraylist on a listview in Android. I've also tried using \u00a0 inside of &nbsp inside the if statement but that doesn't work either.Is there another way of doing this or am I doing something wrong? I don't know if this problem is Java -related or Android-related. Thanks for any help.


0 comments:

Post a Comment