ANDROID.使用自定义的Android ListView项目和自定义的ArrayAdapter.从Web检索图像



嗨,我正在使用自定义android listview与自定义arrayadapter从本网站的教程为我的应用程序。

http://www.ezzylearning.com/tutorial.aspx?tid=1763429

在MainActivity.java中他们有:

Weather weather_data[] = new Weather[]
    {
        new Weather(R.drawable.weather_cloudy, "Cloudy"),
        new Weather(R.drawable.weather_showers, "Showers"),
        new Weather(R.drawable.weather_snow, "Snow"),
        new Weather(R.drawable.weather_storm, "Storm"),
        new Weather(R.drawable.weather_sunny, "Sunny")
    };

我想做的是从网上检索图像,如http://spe.atdmt.com/ds/NMMRTSMGUWDS/121114_reddit/Win8_wiki_728x90_v2.jpg

并使用它来代替R.drawable。

我尝试将URL链接转换为位图图像,然后在

中更改几行代码

Weather.java:

from public int icon; to public Bitmap icon;

from public Weather(int icon, String title) to public Weather(Bitmap icon, String title)

WeatherAdapter.java:

from holder.imgIcon.setImageResource(weather.icon); to holder.imgIcon.setImageBitmap(weather.icon);

我一定不能完全理解代码。我希望有人能帮帮我。谢谢你

那么,您必须从实际下载图像开始(例如,使用这个实现)。当您异步下载映像到某个临时目录后,您可以使用BitmapFactory打开这些文件并获得所需的Bitmap对象。

您还应该查看延迟加载图像到您的ListView

最新更新