我有一个网格视图,它显示SD卡显示的一些图像正确显示但只有当我滚动它一次又一次地加载图像这就是为什么滚动太慢我不知道为什么它每次加载图像我滚动(图像未显示在屏幕内。)
我的代码
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (c.moveToFirst())
{
do
{
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.grid_row_view, null);
holder = new ViewHolder();
holder.ImgThumb = (ImageView) convertView.findViewById(R.id.imgThumb);
holder.Viewcover = (ImageView) convertView.findViewById(R.id.cover);
holder.PdfUrl = (TextView) convertView.findViewById(R.id.hiddenPdfUrl);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
String imagePath = Environment.getExternalStorageDirectory().toString() + "/ICA Faculty/";
holder.ImgThumb.setImageDrawable(Drawable.createFromPath(imagePath + imgUrl.get(position)));
holder.Viewcover.setImageResource(R.drawable.book_cover);
holder.PdfUrl.setText(pdfUrl.get(position));
} while (c.moveToNext());
}
return convertView;
}
private class ViewHolder {
ImageView ImgThumb;
ImageView Viewcover;
TextView PdfUrl;
}
答案 0 :(得分:1)
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
//final boolean result = ( position == 0 ) ? c.moveToFirst() : c.moveToNext();
if (c.moveToPosition(position))
{
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.grid_row_view, null);
holder = new ViewHolder();
holder.ImgThumb = (ImageView) convertView.findViewById(R.id.imgThumb);
holder.Viewcover = (ImageView) convertView.findViewById(R.id.cover);
holder.PdfUrl = (TextView) convertView.findViewById(R.id.hiddenPdfUrl);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
String imagePath = Environment.getExternalStorageDirectory().toString() + "/ICA Faculty/";
holder.ImgThumb.setImageDrawable(Drawable.createFromPath(imagePath + imgUrl.get(position)));
holder.Viewcover.setImageResource(R.drawable.book_cover);
holder.PdfUrl.setText(pdfUrl.get(position));
}
return convertView;
}
适配器的getCount
内部方法返回c.getCount();
答案 1 :(得分:1)
那是因为您为每张图片加载全部图像...如果您正在使用光标,请考虑使用SimpleCursorAdapter。