Sorry, I realized in that above example I passed to arguments to
execute(), not that it makes any difference to my issue.

On Oct 12, 11:58 pm, Lee Jarvis <ljjar...@googlemail.com> wrote:
> Ok so I kind of implemented this, but it forces close when I click the
> button.. What am I doing wrong?
>
> ================================
> package net.gullycorp.example.webtest;
>
> import java.io.IOException;
>
> import org.apache.http.client.ClientProtocolException;
>
> import android.app.Activity;
> import android.app.AlertDialog;
> import android.content.DialogInterface;
> import android.os.AsyncTask;
> import android.os.Bundle;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
> import android.widget.EditText;
> import android.widget.TextView;
> import android.widget.Toast;
>
> public class WebTest extends Activity implements OnClickListener {
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>         Button clickme = (Button) findViewById(R.id.clickme);
>         clickme.setOnClickListener(this);
>
>     }
>
>     public void onClick(View view) {
>         int id = view.getId();
>
>         switch(id) {
>         case R.id.clickme:
>                 EditText urlText = (EditText) findViewById(R.id.textbox);
>                 String url = urlText.getText().toString();
>                 grabSource(url);
>                 break;
>         }
>     }
>
>     private void grabSource(String url) {
>         new GrabURLTask().execute();
>     }
>
>     private class GrabURLTask extends AsyncTask<String, Void, Void> {
>         protected void onPreExecute() {
>                 Utilities.showToast(WebTest.this, "Loading..", true);
>         }
>
>                 protected Void doInBackground(String... params) {
>                         final Webat client = new Webat();
>                         boolean success = false;
>
>                         try {
>                                 client.getURL(params[0]);
>                                 success = true;
>                         } catch (ClientProtocolException e) {
>                                 Utilities.showToast(WebTest.this, 
> e.getMessage(), true);
>                                 cancel(true);
>                         } catch (IOException e) {
>                                 Utilities.showToast(WebTest.this, 
> e.getMessage(), true);
>                                 cancel(true);
>                         }
>                         return null;
>                 }
>
>                 protected void onPostExecute(Void unused) {
>                         Utilities.showToast(WebTest.this, "Source loaded.", 
> true);
>                 }
>
>     }
>
> }
>
> ===========================================
>
> Apologies for the large paste, I can pastie it if it's preferable?
>
> Thanks,
> Lee
>
> On Oct 11, 11:24 pm, Mark Murphy <mmur...@commonsware.com> wrote:
>
>
>
> > LeeJarviswrote:
> > > Oh, I don't plan on using half of the dialogs and such I'm using in
> > > that test application. I too prefer to write things in an activity
> > > over a dialog. I just want to get this to work.
>
> > > Unfortunately I'm getting confused as hell. I can see how this should
> > > be implemented, but I can't get it to do so. I guess I'll try and find
> > > some examples of using AsyncTask that aren't too complex.
>
> > Yeah, AsyncTask went a bit overboard with the varargs and such, IMHO.
>
> > My EndlessAdapter component has about as trivial of an AsyncTask
> > implementation as you'll find:
>
> >http://github.com/commonsguy/cwac-endless
>
> > --
> > Mark Murphy (a Commons 
> > Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> > _Android Programming Tutorials_ Version 1.0 Available!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to