我收到被存储为BLOB从我SQLite数据库图像和光标这样的SimpleCursorAdapter设置为适配器:的Android - SimpleCursorAdapter缓慢的图像加载
public class FragmentAdapter3 extends Fragment {
ArrayList<Sudentdb> list;
GridView gridView;
final String[] from = new String[]{SQLiteHelper._ID,
SQLiteHelper.NAME, SQLiteHelper.AGE, "imagepath"};
final int[] to = new int[]{R.id.rowid, R.id.txtName, R.id.txtAge, R.id.img};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_main_adapter3, null);
gridView = (GridView) v.findViewById(R.id.gridView);
empty = (TextView) v.findViewById(R.id.esc);
final DBManager dbManager = new DBManager(getActivity());
dbManager.open();
final Cursor cursor = dbManager.fetch();
list = new ArrayList<>();
gridView.setAdapter(new SimpleCursorAdapter(getActivity(), R.layout.single_item, cursor, from, to, 0));
return v;
}
这工作得很好,我”从SQLite获取所有文本和图像,问题是图像加载非常缓慢,这导致我的应用程序在活动之间切换时“滞后”。
我的问题是,如何在使用SimpleCursorAdapter的情况下从我的SQLite数据库加载图像,而不会在切换活动时导致延迟/加载问题?
编辑:
我知道我可以使用图书馆像Piccaso,UniversalImageLoader或排球,能够处理图像的缓存我,但我不知道我将如何与String[]
实现它像上面一样。
编辑2:
现在我保存和获取图像的路径类似的意见建议,但出现相同的问题。在日志中发生的唯一事情是:
Skipped 43 frames! The application may be doing too much work on its main thread.
这表明,我认为这是导致此问题,甚至改变储蓄BLOB节省文件路径后,图像的加载。
请勿使用BLOBS存储大图像 - 使用普通文件,并将路径存储到您的sqlite数据库 – pskink
首先,为什么您需要将图像存储在数据库而不是图像路径中? – Aks4125
@pskink请参阅edit2 – ClassA