有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从OpenWeatherMap获取图标

我想得到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

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


共 (1) 个答案

  1. # 1 楼答案

    图标的文档在这里

    http://openweathermap.org/weather-conditions

    您将从JSON调用返回的对象中获取图标代码, 如你的问题所示,然后用它构建一个指向图标的url

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

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

    将此添加到您的构建中。格雷德尔档案-

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

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

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

    希望这有帮助