title: Show data from world weather online api
body: <p>I am developing weather application by using world weather online API 
   for android.How i show data in application? data is showing in logcat.Following is my code.</p>
  
  <p><code>MainActivity.java</code></p>
  
  <p>public class MainActivity extends ListActivity {</p>
  
  <pre><code>private ProgressDialog pDialog;
  
  // URL to get contacts JSON
  private static String url = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=";
  
  // JSON Node names
  private static final String TAG_DATA = "data";
  private static final String TAG_NAME = "name";
  // contacts JSONArray
  JSONArray data = null;
  
  // Hashmap for ListView
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; dataList;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      dataList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      ListView lv = getListView();
  
      new GetContacts().execute();
  }
  
  /**
   * Async task class to get json by making HTTP call
   * */
  private class GetContacts extends AsyncTask&lt;Void, Void, Void&gt; {
  
      protected void onPreExecute() {
          super.onPreExecute();
          // Showing progress dialog
          pDialog = new ProgressDialog(MainActivity.this);
          pDialog.setMessage("Please wait...");
          pDialog.setCancelable(false);
          pDialog.show();
  
      }
  
      @Override
      protected Void doInBackground(Void... arg0) {
          // Creating service handler class instance
          ServiceHandler sh = new ServiceHandler();
  
          // Making a request to url and getting response
          String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
  
          Log.d("Response: ", "&gt; " + jsonStr);
  
          if (jsonStr != null) {
              try {
                  JSONObject jsonObj = new JSONObject(jsonStr);
  
                  // Getting JSON Array node
                  data = jsonObj.getJSONArray(TAG_DATA);
  
                  // looping through All Contacts
                  for (int i = 0; i &lt; data.length(); i++) {
                      JSONObject c = data.getJSONObject(i);
  
  
  
                      // tmp hashmap for single contact
                      HashMap&lt;String, String&gt; contact = new HashMap&lt;String, String&gt;();
  
                      // adding each child node to HashMap key =&gt; value
  
  
                      // adding contact to contact list
                      dataList.add(contact);
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          } else {
              Log.e("ServiceHandler", "Couldn't get any data from the url");
          }
  
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
          super.onPostExecute(result);
          // Dismiss the progress dialog
          if (pDialog.isShowing())
              pDialog.dismiss();
          /**
           * Updating parsed JSON data into ListView
           * */
          ListAdapter adapter = new SimpleAdapter(MainActivity.this,
                  dataList, R.layout.list_item, new String[] { TAG_NAME }, new int[] {
                          R.id.name });
  
          setListAdapter(adapter);
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><code>ServiceHandler.java</code></p>
  
  <p>public class ServiceHandler {</p>
  
  <pre><code>static String response = null;
  public final static int GET = 1;
  public final static int POST = 2;
  
  public ServiceHandler() {
  
  }
  
  /**
   * Making service call
   * @url - url to make request
   * @method - http request method
   * */
  public String makeServiceCall(String url, int method) {
      return this.makeServiceCall(url, method, null);
  }
  
  /**
   * Making service call
   * @url - url to make request
   * @method - http request method
   * @params - http request params
   * */
  public String makeServiceCall(String url, int method,
          List&lt;NameValuePair&gt; params) {
      try {
          // http client
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpEntity httpEntity = null;
          HttpResponse httpResponse = null;
  
          // Checking http request method type
          if (method == POST) {
              HttpPost httpPost = new HttpPost(url);
              // adding post params
              if (params != null) {
                  httpPost.setEntity(new UrlEncodedFormEntity(params));
              }
  
              httpResponse = httpClient.execute(httpPost);
  
          } else if (method == GET) {
              // appending params to url
              if (params != null) {
                  String paramString = URLEncodedUtils
                          .format(params, "utf-8");
                  url += "?" + paramString;
              }
              HttpGet httpGet = new HttpGet(url);
  
              httpResponse = httpClient.execute(httpGet);
  
          }
          httpEntity = httpResponse.getEntity();
          response = EntityUtils.toString(httpEntity);
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      return response;
  
  }
  </code></pre>
  
  <p>}</p>