我试图让天气API更改为输入EditText框的值。我的天气API就是:" http://api.openweathermap.org/data/2.5/weather?q= ***城市位置*** uk& appid = *** API KEY *** 1& units = Imperial"
我想这样做,以便API中的CITY LOCATION部分更改为我的EditText的值。如果我手动输入"伦敦"或"利物浦"我的API有效。代码中的等等,但我希望用户能够进入他们选择的城市,然后更新到当前城市的天气。
这是我的代码:
EditText editCity;
editCity = (EditText) findViewById(R.id.editCity);
String url5 = editCity.getText().toString();
String url [] = {"http://api.openweathermap.org/data/2.5/weather?q=" + url5 + "uk&appid=fb7a0115dacfcfc60b3591a367e07181&units=Imperial"};
JsonObjectRequest jor = new JsonObjectRequest(Request.Method.GET, url[0], null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try
{
JSONObject main_object = response.getJSONObject("main");
JSONArray array = response.getJSONArray("weather");
JSONObject object = array.getJSONObject(0);
String temp = valueOf(main_object.getDouble("temp"));
String description = object.getString("description");
String city = response.getString("name");