title: AsyncTask in a Loop In Android
body: <p>I am creating a app that will update the weather details of the city.The loop will be a List of City .So i want as much the cities are in there in the List.I will use the  AsyncTask method to send the request and parse it.And at the same time i am inflating a layout and i have to put all the weather details corresponding to the city in the Layout .How could i achieve this please help me in this.</p>
  
  <p><strong>XML</strong> file that i am inflating</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/depart_details"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
  
      &lt;ImageView
          android:id="@+id/flight_depart_image"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:padding="3dip"
          android:layout_marginTop="10dp"
          android:src="@drawable/f1" /&gt;
  
      &lt;TextView
          android:id="@+id/depart_time"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:layout_marginTop="5dp"
          android:layout_toRightOf="@+id/flight_depart_image"
          android:text=""
          android:textColor="#666666"
          android:textSize="25sp"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/depart_airport_city"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:layout_marginTop="5dp"
          android:layout_toRightOf="@+id/depart_time"
          android:text=""
          android:textColor="#666666"
          android:textSize="15sp"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/depart_airport"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/depart_airport_city"
          android:layout_marginLeft="125dp"
          android:text="N/A"
          android:textColor="#666666"
          android:textSize="12sp"
          android:textStyle="bold" /&gt;
  
      &lt;ImageView
          android:id="@+id/weather_image"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft ="40dp"
          android:layout_toRightOf="@+id/depart_airport"
          android:src="@drawable/image" /&gt;
  
      &lt;TextView
          android:id="@+id/tempraturetext"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="3dp"
          android:layout_toRightOf="@+id/weather_image"
          android:text="Temp:" /&gt;
  
      &lt;TextView
          android:id="@+id/temprature"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="3dp"
          android:layout_toRightOf="@+id/tempraturetext"
          android:text="20℃" /&gt;
  
      &lt;TextView
          android:id="@+id/humidity_text"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/temprature"
          android:layout_marginLeft="3dp"
          android:layout_toRightOf="@+id/weather_image"
          android:text="Humidity:" /&gt;
  
      &lt;TextView
          android:id="@+id/humidity"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/temprature"
          android:layout_marginLeft="3dp"
          android:layout_toRightOf="@+id/humidity_text"
          android:text="32" /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="1dp"
          android:layout_below="@+id/depart_airport"
          android:layout_marginTop="5dp"
          android:background="#d3d3d3" &gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>this function i have created to send the request </p>
  
  <pre><code>private WeatherResponse requestWeatherUpdate(String location) {
          url = "" + location; //This location will be dyanamic and multiple
          Log.d("URL for Weather Upadate", url);
          WeatherUpdate weatherReq = new WeatherUpdate(new CallBack() {
              @Override
              public void run(Object result) {
                  try {
                       AppResponse = (String) result;
                      response = ParseWeatherResponseXML
                              .parseMyTripXML(AppResponse);
  
                  } catch (Exception e) {
                      Log.e("TAG Exception Occured",
                              "Exception is " + e.getMessage());
                  }
              }
          });
          weatherReq.execute(url);
          return response;
  
      }
  </code></pre>
  
  <p><strong>AsynkTask</strong></p>
  
  <pre><code>public class WeatherUpdate extends AsyncTask&lt;String, Void, String&gt; {
      Context context;
      CallBack callBack;
  
      public WeatherUpdate(CallBack callBack) {
          this.callBack = callBack;
      }
  
      @Override
      protected String doInBackground(String... arg0) {
          String responseString = "";
          HttpClient client = null;
          try {
              client = new DefaultHttpClient();
              HttpGet get = new HttpGet(IweenTripDetails.url);
              client.getParams().setParameter("http.socket.timeout", 6000);
              client.getParams().setParameter("http.connection.timeout", 6000);
              HttpResponse responseGet = client.execute(get);
              HttpEntity resEntityGet = responseGet.getEntity();
              if (resEntityGet != null) {
                  responseString = EntityUtils.toString(resEntityGet);
                  Log.i("GET RESPONSE", responseString.trim());
              }
          } catch (Exception e) {
              Log.d("ANDRO_ASYNC_ERROR", "Error is " + e.toString());
          }
          Log.d("ANDRO_ASYNC_RESPONSE", responseString.trim());
          client.getConnectionManager().shutdown();
          return responseString.trim();
      }
  
      @Override
      protected void onPostExecute(String result) {
          // TODO Auto-generated method stub
          super.onPostExecute(result);
          callBack.run(result);
  
      }
  
  }
  </code></pre>