gpt4 book ai didi

java - 如何从 OpenWeatherMap 获取图标

转载 作者:行者123 更新时间:2023-12-02 02:39:52 29 4
gpt4 key购买 nike

我想要获取 openweathermap 图标。 https://openweathermap.org/weather-conditionshttp://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1图标是字符串值。我创建了 imageView 但我没有创建

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int position, long id) {
String text = (String) listView.getItemAtPosition(position);



Factory.getInstance().havaModel(text,APPID_KEY).enqueue(new Callback<HavaModel>() {
@Override
public void onResponse(Call<HavaModel> call, Response<HavaModel> response) {
textView.setText(Float.toString((float) (response.body().main.temp-273.15)));
textView2.setText(Float.toString(response.body().coord.lon));
textView3.setText(Integer.toString(response.body().main.humidity));
textView4.setText(response.body().name);
imageView.getResources()



}

enter image description here

非常感谢。您的建议对我很重要

最佳答案

图标的文档位于此处。

http://openweathermap.org/weather-conditions

您将从 JSON 调用返回的对象中获取图标代码,正如你的问题中给出的,然后用它来构造一个指向图标的网址,

String iconUrl = "http://openweathermap.org/img/w/" + iconCode + ".png";

您还可以使用图像加载库将图像加载到 ImageView 中 - 例如:- 使用 Picasso Image Library -

将其添加到您的 build.gradle 文件中 -

compile 'com.squareup.picasso:picasso:2.5.2'

然后使用下面的代码将图像加载到 ImageView 中 -

Picasso.with(context).load(iconUrl).into(imageView);

希望这有帮助!

关于java - 如何从 OpenWeatherMap 获取图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45673935/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com