【问题标题】:ANDROID. Using a Customized Android ListView Items with Custom ArrayAdapter. Retrieving Images From Web安卓。使用带有自定义 ArrayAdapter 的自定义 Android ListView 项目。从 Web 检索图像
【发布时间】:2013-01-05 10:58:50
【问题描述】:

您好,我正在为我的应用程序使用本网站教程中的自定义 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 链接转换为位图图像,然后在

中更改几行代码

天气.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);

我不能完全理解代码。我希望有人可以在这里帮助我。谢谢

【问题讨论】:

    标签: android bitmap android-arrayadapter


    【解决方案1】:

    好吧,您必须从实际下载图像开始(例如,使用this implementation)。将图像异步下载到某个临时目录后,您可以使用BitmapFactory 打开这些文件并获取您需要的Bitmap 对象。

    您还应该查看lazy loading the images 到您的ListView。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多