为什么文本显示在一行?

好吧,我的代码有问题,我需要从URL(代码:php)下载代码,在Android平台上使用JSOUP。该站点看起来不错(数据由ENTER分隔),并且在应用程序中所有内容都写在一个字符串中,我无法根据您的需要进行调整。即,我希望页面中的数据在应用程序中排列相同。


private void getWebsite(){

         new Thread(new Runnable() {

        @Override

        public void run() {

            final StringBuilder builder = new StringBuilder();


            try {


                Document doc = Jsoup.connect("https://k69.pl/odtwarzacz/aplikacjaRadia.php").get();


                Elements links = ((Document) doc).select("body");



                    for(Element link : links){


                    builder.append(link.attr("<br>")).append(link.text());



                }


            } catch (IOException e){

                builder.append("Aplikacja nie mogła wykonać żądania. Zgłoś ten błąd do administratora aplikacji. Twój błąd to : ").append(e.getMessage()).append("\n");

            }



            runOnUiThread(new Runnable() {

                @Override

                public void run() {

                    wynik.setText(builder.toString());

                }

            });


        }

    }).start();





}

该网站的结果:


https://imgur.com/a/LrE3oOH


应用程序的结果:


https://imgur.com/a/IlotHa6


宝慕林4294392
浏览 128回答 3
3回答

不负相思意

适用于 HTML,因此,如果您正在为可以正常工作的 web 视图构建 HTML。但是,您正在设置一个 Text,因此 HTML 标记不会被理解或遵守。而不是设置文本,你应该做builder.append(link.attr("\n")).append(link.text());快乐编码!

慕哥9229398

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Document doc = Jsoup.connect("https://k69.pl/odtwarzacz/aplikacjaRadia.php").get();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Elements links = ((Document) doc).select("div");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(Element link : links){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; builder.append(links.attr("\n")).append(links);山姆,我更改了代码,现在我得到了这样的结果(https://imgur.com/a/ts8FPhJ)。如何摆脱这个 div 和 br?link.text() <= 使文本在一行中继续

慕桂英546537

感谢您的帮助,我做了不同的事情,它可以按我的意愿工作。在字符串上交换元素“JSOUP”。&nbsp;for(Element link : links){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String tresc = links.toString();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String[] x;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String zamien;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zamien =&nbsp; tresc.replace("<br>","");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x = zamien.split("\n");
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java