-4

How do I return multiple links I get from this website? The return I have outside the loop doesn't seem to work.

public class jsoupexample extends AsyncTask<String,Integer,String>{
    @Override
    protected String doInBackground(String... html) {
        try {
            doc = Jsoup.connect(html[0]).get();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Elements link = doc.select("a[href]");

        for(Element links : link) {
            audi=links.attr("abs:href");
        }
        return audi;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        tv2.setText(result);
    }

}
thegrinner
  • 11,546
  • 5
  • 41
  • 64
Gunjit Dhawan
  • 157
  • 1
  • 9

2 Answers2

3

You must try to get all those values and collect them in a list or String array object, using your for loop, and then return that object in doInBackground, so that you can later use in your onPostExecute.

Use AsyncTask: where does the return value of doInBackground() go? for more assistance.

Community
  • 1
  • 1
Narendra Singh
  • 3,990
  • 5
  • 37
  • 78
0

Try this

Just add plus Symbol to concat the values like this

  for(Element links : link) {
            audi+=links.attr("abs:href");
        }
Pragnani
  • 20,075
  • 6
  • 49
  • 74