我正在尝试显示带有商品的ListView.商品是一个带有标题,数量和图像(BLOB)的SQLite表.所以我的ListView不流畅.
我尝试了什么:
>打开摄像机意图,进行捕获,获取Extras并插入SQLite.所以我只用了一个位图.此方法一直有效,直到商品数量少于50.
我走了另一条路:
>打开相机意图,捕获并保存到文件.
>检查ExifInterface并根据需要旋转图像.
>使用http://developer.android.com/training/displaying-bitmaps/load-bitmap.html缩放到300×300,然后移动到我的文件夹.该图像文件用于全屏显示.
>现在,我需要一个缩略图,以便将来将其放入ListView.所以我使用http://developer.android.com/training/camera/photobasics.html中的setPic()方法将file(3)缩放到缩略图大小(例如60×60)
并将这个小拇指保存到SQLite数据库商品表中.
现在,当商品数量超过100时,ListView变得难以滚动.这不是问题的解决方案.
所以我需要一些不同的方法来用图像填充ListView.
请以正确的方式指导我)))
谢谢!
附言我正在使用自定义的SimpleCursorAdapter来显示数据:
public class GoodsCursorAdapter extends SimpleCursorAdapter {
public GoodsCursorAdapter(Context context) {
super(context, R.layout.cell_goods, null,
new String[] { "title", "countAvail" },
new int[] { R.id.lbTitle, R.id.lbCount }, 0);
}
private class ViewHolder {
ImageView imageView;
TextView lbTitle, lbCount;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null){
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.cell_goods, parent, false);
viewHolder = new ViewHolder();
viewHolder.imageView = (ImageView) convertView.findViewById(R.id.ivThumb);
viewHolder.lbTitle = (TextView) convertView.findViewById(R.id.lbTitle);
viewHolder.lbCount = (TextView) convertView.findViewById(R.id.lbCount);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
mainCursor.moveToPosition(position);
byte[] byteArray = mainCursor.getBlob(mainCursor.getColumnIndex("photo"));
if (byteArray != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
Log.d("INFO", mainCursor.getString(mainCursor.getColumnIndex("title"))+": "+String.valueOf(bitmap.getWidth())+"x"+String.valueOf(bitmap.getHeight())+"("+String.valueOf(bitmap.getByteCount()/1024)+"Kb)");
viewHolder.imageView.setImageBitmap(bitmap);
} else {
viewHolder.imageView.setImageResource(R.drawable.ic_action_picture);
}
viewHolder.lbTitle.setText(mainCursor.getString(mainCursor.getColumnIndex("title")));
viewHolder.lbCount.setText(String.format(getString(R.string.lbCount), mainCursor.getString(mainCursor.getColumnIndex("countAvail"))));
return convertView;
}