enter image description here

public class NewThread extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... arg) { Document doc; try { doc = Jsoup.connect("https://сайт").maxBodySize(0).get(); content = doc.select("елемент"); titleList.clear(); progressBar = (ProgressBar) findViewById(R.id.progressBar); for (Element contents : content) { titleList.add(contents.text()); progress = progress + 10; progressBar.setProgress(progress); } } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String result) { lv.setAdapter(adapter); } 
  • I would update the idea if I were you - michael_best

1 answer 1

The doInBackground method doInBackground not have access to the UI stream. in order to pass values ​​to a UI stream, you need to use the publishProgress() method, which passes the values ​​to onProgressUpdate() , which already has access to the UI stream.

 public class NewThread extends AsyncTask<String, Integer, String> { @Override protected String doInBackground(String... arg) { Document doc; try { doc = Jsoup.connect("https://сайт").maxBodySize(0).get(); content = doc.select("елемент"); titleList.clear(); for (Element contents : content) { titleList.add(contents.text()); progress = progress + 10; publishProgress(progress); } } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); progressBar = (ProgressBar) findViewById(R.id.progressBar); progressBar.setProgress(values[0]); } @Override protected void onPostExecute(String result) { lv.setAdapter(adapter); } 

  • I can't use the publishProgress () method, I swap it with the doInBackground and get even more errors. (You can write an example of how to embed it in my code) - YOUR REALITY.
  • You copied my code and it did not work for you? or did you just add publishProgress() to doInBackground - Eugene Nikolaev
  • copy the whole class to yourself - Evgeny Nikolaev
  • I will try now thanks - YOUR REALITY.
  • You are simply the best works perfect))) THANKS - ITS REALITY.