Issue with parsed text with HTMLCleaner - spaces at the begining of text

Posted by ansol90 on Stack Overflow See other posts from Stack Overflow or by ansol90
Published on 2012-11-12T22:52:57Z Indexed on 2012/11/12 23:00 UTC
Read the original article Hit count: 323

Filed under:
|

Im able to get text using HTMLCleaner from website. The problem is that when I set the text to a TextView it shows the beginning of the text with a big space on it. Here is the screenshot of what im talking about.

I have tried android:gravity but nothing happened.

Please help.

Here is my Code:

    private class SiteParser extends AsyncTask<String, Void, String> {

    protected String doInBackground(String... arg) {
        String output = null;

        try {
            HtmlHelper hh = new HtmlHelper(new URL(arg[0]));
            List<TagNode> news = hh.getnewsByClass("TextoPrint");

            for (Iterator<TagNode> iterator = newss.iterator(); iterator
                    .hasNext();) {
                TagNode divElement = (TagNode) iterator.next();
                output = divElement.getText().toString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return output;
    }

    protected void onPostExecute(String output) {


        Bundle bundle=new Bundle();
        bundle.putString("body",output);
        Intent mainIntent = new Intent(act, MyView.class);
        mainIntent.putExtras(bundle);
                startActivity(mainIntent);
        act.finish();



    }
}

public class HtmlHelper {
    TagNode rootNode;

    public HtmlHelper(URL htmlPage) throws IOException, XPatherException {
        HtmlCleaner cleaner = new HtmlCleaner();
        rootNode = cleaner.clean(htmlPage);

    }

    List<TagNode> getnewsByClass(String Classname){
        List<TagNode> newsList = new ArrayList<TagNode>();


        TagNode divElements[] = rootNode.getElementsByName("div", true);
        for (int i = 0; divElements != null && i < divElements.length; i++) {
            String classType =  divElements[i].getAttributeByName("id");
            if (classType != null && classType.equals(Classname)) {
                newsList.add(divElements[i]);
            }
        }

        return newsList;
    }
}

© Stack Overflow or respective owner

Related posts about android

Related posts about htmlcleaner