【发布时间】:2013-03-14 11:56:18
【问题描述】:
多年来我一直在访问 Stack Overflow,这是我第一次找不到任何可以解决我问题的帖子(至少我没有看到任何帖子)。
我有一个带有自定义适配器的GridView,我已将其覆盖以返回由ImageView 和TextView 创建的自定义视图。
我从带有AsyncTask 的URL 中进行JSON 解析后加载图像,将所有信息存储到doInBackground() 方法中的ArrayList 中,并在onPostExecute() 方法中调用notifyDataSetChanged()。一切都很好。
现在我的问题是,当我启动活动时,网格视图需要 5-10 秒的时间才能创建并以实体形式呈现给用户。我想知道是否有一种方法可以先显示带有文本信息的网格视图,然后再加载每个图像。这是否可能,因为它们都是以相同的方法创建的?
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
View v = null;
if (arg1 == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.custom_product_view, null);
} else {
v = arg1;
}
iv = (ImageView) v.findViewById(R.id.product_image);
imageLoader.DisplayImage(products.get(arg0).getImage(), iv);
TextView tv = (TextView) v.findViewById(R.id.product_price);
tv.setText(products.get(arg0).getPrice());
return v;
}
我还必须通知您,正如您从 DisplayImage() 方法中看到的那样,我已经实现了这个延迟加载:Lazy load of images in ListView。它工作正常,但问题是它再次加载了整个视图。我想要做的是启动活动,首先加载标题,然后在完成下载后加载图像。使用这里的代码,它只是延迟加载网格视图的每个单元格包含的整个视图。我赢得了几秒钟,因为我没有像以前那样一次下载所有图像,但它仍然不是我要搜索的。
非常感谢。
【问题讨论】:
标签: android android-custom-view android-gridview android-lazyloading