Give the task a callback which you call from onPostExecute.

On Dec 16, 3:37 pm, jeremy <[email protected]> wrote:
> Hi,
>
> As stated in the title, I need help on this. I am downloading content
> from a http connection and storing the contents in String array
> mStrings[] and dStrings[]. But how do I pass the values from the
> asynctask to the arrays in main activity? Thanks
>
> Activity.java
>
>     ListView list;
>     LazyAdapter adapter;
>
>     ProgressDialog dialog;
>     private String[] mStrings = {};
>     private String[] dStrings = {};
>
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.cats);
>
>         new TheTask().execute();
>
>         list=(ListView)findViewById(R.id.list);
>         adapter=new LazyAdapter(this, mStrings, dStrings);
>         list.setAdapter(adapter);
>
>     }
>
>     private class TheTask extends AsyncTask<Void, Void, Void>{
>
>         @Override
>         protected void onPreExecute() {
>                 dialog = ProgressDialog.show(Activity.this, "Retrieving
> Information", "Please wait for few seconds...", true, false);
>                 dialog.setCancelable(true);
>         }
>         @Override
>         protected Void doInBackground(Void... params) {
>                 searchContent();
>                         return null;
>         }
>
>         protected void onPostExecute(Void... params) {
>                 dialog.dismiss();
>         }
>     }
>
>     public void searchContent()
>         {
>         String imageC = "";
>         String textC = "";
>
>         try {
>                 // Get the URL from text box and make the URL object
>
>                 URL url = new URL(targetURL);
>
>                 // Make the connection
>                 URLConnection conn = url.openConnection();
>                 BufferedReader reader = new BufferedReader(
>                  new InputStreamReader(conn.getInputStream()));
>
>                 String line = reader.readLine();
>                 Pattern sChar = Pattern.compile("&.*?;");
>                 line.replaceAll("\\<.*?\\>", "");
>             Matcher msChar = sChar.matcher(line);
>             while (msChar.find()) line = msChar.replaceAll("");
>
>                 while (line != null) {
>
>                         if(line.contains("../../"))
>                         {
>
>                                 int startIndex = line.indexOf("../../") + 6;
>
>                                 imageC += line +";";
>                         mStrings = imageC.split(";");
>                                 line = reader.readLine();
>                         }
>
>                         if(line.contains("../../") == false)
>                         {
>                                 line = reader.readLine();
>                         }
>
>                         if (line.contains("Gnametag"))
>                         {
>                                 int startIndex = line.indexOf("Gnametag") + 
> 10;
>                                 int endIndex = line.indexOf("<", startIndex + 
> 1);
>                                 String gname = 
> line.substring(startIndex,endIndex);
>                                 textC = textC.replaceAll("</span>", "");
>                                 textC += "Name: "+gname+ "\n";
>                         }
>
>                                 if (line.contains("Gender"))
>                                 {
>                                 int startIndex2 = line.indexOf("Gender") + 0;
>                                 int endIndex2 = line.indexOf("<", startIndex2 
> + 1);
>                                 String gender = 
> line.substring(startIndex2,endIndex2);
>                                 textC += gender +"\n";
>                                 }
>
>                         if (line.contains("Last Update"))
>                         {
>                                 reader.close();
>                         }
>                 }
>
>                 // Close the reader
>                 reader.close();
>
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>             }
>         }
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to