android - Need to use a variable which used in for loop -
I have an asyncTask class and I have to use the variable to show an image in an image view. I use the jsoup library to parse the HTML page and the problem is that I can not take my variable "bitmap" from doInBackground to onPostExecute method. How can I solve my problem? Here's the code:
Private class paras HTML spreads asyncTask; Zero, zero, zero, and gt; {String resultTextFmt; Bitmap bm; @ OverEride Protected Zero at PreExecute () {super.onPreExecute (); MProgressDialog = New Progress Diablog (main activity.); MProgressDialog.setTitle ("WebMD"); MProgressDialog.setMessage ("Loading ..."); MProgressDialog.setIndeterminate (wrong); MProgressDialog.show (); } @ Override Safe Volume Doine Background (Zero ... Parameter) {try {document document = jsoup.connect (murl) .get (); Element description 2 = document. Select ("h2 [class = et_pt_title]"); Logs. V ("Data 3", Description 2. Tosting ()); ResultTextFmt = description2.toString (); Element divs = document.select ("img"); Logs. W ("DIVS_PICS", divs.toString ()); Bitmap bitmap; For (Element Divi: Divis) {Log D. ("Web stuff", div.Text ()); // element myImage = div; String iurl; Iurl = div.absUrl ("src"); Log.w ("ABSurl:", iurl.toString ()); Url url = new url (iurl); Bitmap = bitmapfinder Aodestream (url.openstream ()); // I need to get this var} BM = bitmap; } Hold (exception e) {e.printStackTrace (); } Return tap; } @ Override Secure Zero at PostXextake (zero result) {imgView.setImageBitmap (BM); // and put it here to show textView.setText (Html.fromHtml (resultTextFmt)); MProgressDialog.dismiss (); }}
You must declare your AsyncTask like this:
< Pre> Private class parse HTML has expanded the Ascend Task and LTW, Wide, Bitmap; {Protected void} (super.onPreExecute (@OverridePreExecute);} @ Override protected bitmap DoInBackground (zero ... parameter) {bitmap return value = new Bitmap (); return return value;} @Override secure zero Postaksaktek (bitmap result) {imgView.setImageBitmap (result);}}
as you can see, you as a bitmap for doInBackground ()
Class definition result values can Paramitryjh. this way, you onPostExecute ()
this callback The value will also receive and write it will handle bitmap there.
If you want to make more sophisticated these input Algs, or, for example, how to monitor the process, you have async Task There are official documents about.
Comments
Post a Comment