0
我试图通过从sqlite数据库中提取图片名称来显示一些图片,然后使用该图片名称在可绘制文件夹中查找特定图片并将其显示在我的应用中的图库小部件中。它的作品,但现在的问题是,我有太多的图片,所以它没有任何意义的存储在可绘制的文件夹中的所有内容,因为它会使应用程序太大。我正在考虑在线放置图片,并将单独的url存储到sqlite数据库中。通过这种方式,我可以从数据库获取URL并使用该URL,我可以下载图像并将其显示在图库小部件中。我阅读了关于懒惰列表(荣誉伟大的工作!),但我有问题在我的应用程序实现。下面是我用于图库的当前代码,我不太确定如何修改它以利用Lazy List从联机下载图像。任何帮助是极大的赞赏! =)在图库中使用懒惰列表
protected String pic1, pic2, pic3;
protected int Id, resID1, resID2, resID3;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_details);
Id = getIntent().getIntExtra("ID", 0);
SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT pic1, pic2, pic3 FROM database WHERE _id = ?",
new String[]{""+Id});
pic1 = cursor.getString(cursor.getColumnIndex("pic1"));
pic2 = cursor.getString(cursor.getColumnIndex("pic2"));
pic3 = cursor.getString(cursor.getColumnIndex("pic3"));
resID1 = getResources().getIdentifier(pic1 , "drawable", getPackageName());
resID2 = getResources().getIdentifier(pic2 , "drawable", getPackageName());
resID3 = getResources().getIdentifier(pic3 , "drawable", getPackageName());
Gallery g = (Gallery) findViewById(R.id.photobar);
g.setAdapter(new ImageAdapter(this));
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
resID1,
resID2,
resID3
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Theme);
mGalleryItemBackground = a.getResourceId(
R.styleable.Theme_android_galleryItemBackground,
0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position,
View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
return i;
}
}
对不起,我是新手编程,所以你可以给你一个什么样的例子吗?所以在这种情况下,我会把公共View getView(int position, View convertView,ViewGroup parent){ImageView i = new ImageView(mContext); imageLoader.DisplayImage(pic1,i); i.setImageResource(mImageIds [position]); i.setLayoutParams(new Gallery.LayoutParams(150,100)); i.setScaleType(ImageView.ScaleType.FIT_XY); return i; }但是,整数数组的mImageIds呢? – maxchia