Android 使用带有URL的数据库中的图像
我正在将应用程序中获取的所有数据缓存在SQLite数据库中。。。每当用户没有internet连接时,都会使用数据库中的SimpleCorsorAdapter加载数据。 数据库还包含图像的URL。图像由我正在使用的图像加载框架(Universal image Loader)缓存,因此当我使用数据库中的URL运行该框架时,它将获得缓存的图像。 我的问题是如何在SimpleCursorAdapter中调用此方法? 到目前为止,我只能从数据库中获取所有文本并将它们附加到文本视图Android 使用带有URL的数据库中的图像,android,sqlite,caching,simplecursoradapter,universal-image-loader,Android,Sqlite,Caching,Simplecursoradapter,Universal Image Loader,我正在将应用程序中获取的所有数据缓存在SQLite数据库中。。。每当用户没有internet连接时,都会使用数据库中的SimpleCorsorAdapter加载数据。 数据库还包含图像的URL。图像由我正在使用的图像加载框架(Universal image Loader)缓存,因此当我使用数据库中的URL运行该框架时,它将获得缓存的图像。 我的问题是如何在SimpleCursorAdapter中调用此方法? 到目前为止,我只能从数据库中获取所有文本并将它们附加到文本视图 谢谢你的帮助 所以我终于
谢谢你的帮助 所以我终于自己完成了 我不得不写一个新的方法来扩展CursorAdapter 在那里,我必须用TextView分配我从数据库中获得的所有文本。因此,我也能够给我的图像加载器链接到(缓存)图像加载 这是我的代码:
private static final class MyCursorAdapter extends CursorAdapter {
MyCursorAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mInflater.inflate(R.layout.row_twitter, parent, false);
return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView listtitle = (TextView) view.findViewById(R.id.listtitle);
TextView listusername = (TextView) view.findViewById(R.id.listusername);
TextView listdate = (TextView) view.findViewById(R.id.listdate);
listtitle.setText(cursor.getString(cursor.getColumnIndex(DataDBAdapter.KEY_TWITTER_TWEET)));
listusername.setText(cursor.getString(cursor.getColumnIndex(DataDBAdapter.KEY_TWITTER_USERNAME)));
listdate.setText(cursor.getString(cursor.getColumnIndex(DataDBAdapter.KEY_TWITTER_DATE)));
listtitle.setTextColor(Color.GRAY);
listdate.setTextColor(Color.GRAY);
ImageView iv = (ImageView) view.findViewById(R.id.image);
imageLoader.displayImage(cursor.getString(cursor.getColumnIndex(DataDBAdapter.KEY_TWITTER_IMAGEURL)),
iv, options);
}
LayoutInflater mInflater;
}
这实际上效果很好:)