嗨,我正在使用自定义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
。