title: How alter an API call with user input
body: <p>I'm trying to alter the below code so that it will change the city and the measurement units (i.e. Fahrenheit and Celsius) in the below code. I want the user to be able to type a city name into an EditText field, hit a button, and it will change the weather location to that city. I also want a preferance to be set to display temperature in either Celsius or Fahrenheit. I'm not sure how to do that though. Below is my current code. The String url is the API I need to be changed based on the input. </p>
  
  <p>Does anyone have any Ideas?</p>
  
  <pre><code>String url = "http://api.openweathermap.org/data/2.5/weather?q=Indianapolis&amp;units=imperial&amp;appid=OpenWeatherMapAPIKey";
  
          JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
                  (Request.Method.GET, url, null, new Response.Listener&lt;JSONObject&gt;() {
  
                      @Override
                      public void onResponse(JSONObject responseObject) {
                          //tempTextView.setText("Response: " + response.toString());
                          Log.v("Weather", "Response: " + responseObject.toString());
  
                          try {
                              JSONObject mainJSONObject = `enter code here`responseObject.getJSONObject("main");
                              JSONArray weatherArray = responseObject.getJSONArray("weather");
                              JSONObject firstWeatherObject = weatherArray.getJSONObject(0);
  
                              String temp = Integer.toString((int) Math.round(mainJSONObject.getDouble("temp")));
                              String weatherDescription = firstWeatherObject.getString("description");
                              String city = responseObject.getString("name");
  
                              tempTextView.setText(temp);
                              weatherDescTextView.setText(weatherDescription);
                              cityTextView.setText(city);
  
                              int iconResourceId = getResources().getIdentifier("icon_" + weatherDescription.replace(" ", ""), "drawable", getPackageName());
                              weatherImageView.setImageResource(iconResourceId);
  
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
                      }
                  }, new Response.ErrorListener() {
  
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          // TODO: Handle error
  
                      }
                  });
  
  // Access the RequestQueue through your singleton class.
          RequestQueue queue = Volley.newRequestQueue(this);
          queue.add(jsonObjectRequest);
      }
  </code></pre>