"Schedule" my program with asynctask?
<p>I am trying to display images in a gridView. The images come from an research on an ElasticSearch server. The user give a keyword in a textfield, the result of the query on ElasticSearch is  list of string (urls of images) and the images are displayed in the gridView.</p>

<p>The action when I press a button in order to make the research :</p>

<pre><code>public void sendMessage(View view){

    imgAdapter.clearmThumbIds();  //mThumbs is a list of string (urls image)

    gridView = (GridView) findViewById(R.id.grid_view);
    EditText editText = (EditText) findViewById(R.id.searchBar);
    String message = editText.getText().toString();          
    try {
        eSearchElastic.ESE(imgAdapter,message);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Etape 2");
    gridView.setAdapter(imgAdapter);


}
</code></pre>

<p>eSearchElastic.java</p>

<pre><code>public static void ESE (final ImageAdapter imgAdapter,final String keyword)throws ClientProtocolException, IOException {

AsyncTask&lt;Void, Void, Void&gt; task = new AsyncTask&lt;Void, Void, Void&gt;(){
    @Override
    protected Void doInBackground(Void... params) {

        //Build the query, connect to ElasticServer and receive a list or urls of image as answer
         System.out.println("Etape 1");
        return null;
    }

};
task.execute();}
</code></pre>

<p>And the result of this print Etape2 before Etape1 and I would like this line "gridView.setAdapter(imgAdapter)" is executed only after the background process/thread of eSearchElastic is finished.
How can I do that? </p>
