infinite scroll in android webview

后端 未结 1 1745
半阙折子戏
半阙折子戏 2021-01-15 11:25

i have some local html file and i want to show them with infinite scroll method.

NOTE: i cant change the html content, so please don\'t advice to ad

1条回答
  •  天命终不由人
    2021-01-15 12:07

    OK, i found the problem, if anyone wants to know.

    the problem is that the loadUri() (at least in my case) can not load too many html tag at once (in javascript code i written)

    so, the solution is easy, load tags one by one.

    here is the code i used:

    public ArrayList getNextPageBody(Uri currAddress)
    {
        String html = getHtml(currAddress); // this is the all html tags in the next file
    
        //get body elements as arrayList, using jsoup
        Document doc = Jsoup.parse(html);
        Elements elements = doc.select("body").first().children();
        ArrayList chuncks = new ArrayList();
        for (org.jsoup.nodes.Element el : elements)
        {
            chuncks.add(el.toString());
        }
    
        return chuncks;
    }
    
    public void loadBodyChunk(ArrayList bodyChunks)
    {    
        //show a separator for each page
        bodyChunks.add(0, "javascript:(function() { document.body.innerHTML += '
    ';}())"); loadUrl(bodyChunks.get(0)); for(int i = 1; i < bodyChunks.size(); i++) { String jsResult = "javascript:(function() { document.body.innerHTML += '" + bodyChunks.get(i) + "';}())"; loadUrl(jsResult); } reloadFlag = true; }

    EDIT:

    also: first the 's in String should be replaced with \' :

    body = body.replace("'", "\\'");
    

    then all newline char should be eliminated:

    body = body.replaceAll(System.getProperty("line.separator"), " ");
    

    all problem solved.

    0 讨论(0)
提交回复
热议问题