Mak wrote:
> Hi.
> I'd like to build an application that loads different urls in a
> webview.
> I prefered the webview cause that gives the chance of deleting cache
> and
> things like that.
> But loading an URL in a loop has the effect that everything but the
> webView
> is executed, till the end of the loop.
> 
> for(int i = 0; i < 10; i++) {
>        WebView ansicht = new WebView(getBaseContext());
>        ansicht.loadUrl(adress.toString());
>       setContentView(ansicht);
>       ansicht.clearCache(true);
>       sleep(15000);
>         System.out.println("instead something else");
> }
> 
> i get the print "instead something else" every 15 seconds and after 10
> times
> the url will be loaded.
> 
> Why can't the webView be called in a loop?
> What's my fault?

You're not letting Android do anything.

This is not a WebView thing -- if your code was updating a TextView with
some new text, you would see the same thing.

Android, like many GUI frameworks, works off of a message loop. Method
invocations, such as setting text in a TextView or loading a URL in a
WebView, will only post messages to a queue the loop works off of. Those
messages will not be processed *until you return control to Android* by
exiting onCreate() or whatever other callback you are in.

Generally speaking, don't use sleep() in Android, particularly in UI logic.

Instead, use postDelayed() on the WebView to cause the next URL to be
loaded in sequence after a delay, and get out of onCreate() or wherever
this code is.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.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 [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