Ty sooo much, got it now
On 3月18日, 下午11时01分, Ian Petersen <ispet...@gmail.com> wrote:
> On Wed, Mar 18, 2009 at 9:38 PM, maple...@gmail.com <maple...@gmail.com>
> wrote:
> > is there a way to force callback to be excuted before next line?
>
> Nope. See
> here:http://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa...
>
> One option is to define a new callback interface and pass an instance
> to GetData. That way you can define the instance in the "other file"
> and still be a good browser citizen.
>
> For example:
>
> public interface SearchResultListener {
>
> void onNewSearchResult(String result);
>
> }
>
> public class GetData {
>
> public void search(String query, final SearchResultListener listener) {
> String url = URL.encode(DEFAULT_URL + "?query=" + query);
> RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
>
> builder.setCallback(new RequestCallback() {
> public void onError(Request request, Throwable exception) {
> // handle problems here
> }
>
> public void onResponseReceived(Request request, Response response) {
> if (Response.SC_OK == response.getStatusCode()) {
> listener.onNewSearchResult(response.getText());
> }
> else {
> // handle problems here
> }
> }
> });
>
> try {
> builder.send();
> }
> catch (RequestException e) {
> // handle problems here
> }
> }
>
> }
>
> Then, if you have an instance of GetData, you can do this:
>
> aGetData.search("query", new SearchResultListener() {
>
> public void onNewSearchResult(String result) {
> System.out.println(result);
> }
>
> });
>
> Ian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---