【发布时间】:2014-10-02 07:59:44
【问题描述】:
嘿,我的问题是如何加快我的 listView 的加载速度……因为我遇到的问题是,由于 ImageView,它真的很懒惰。但是我怎么能在我的缓存中加载图片呢? 我正在使用简单的游标适配器从我的 Sql 数据库中加载数据。这是我的代码:
void populateListViewFromDB() {
Cursor cursor = myDb.getAllRows();
// Allow activity to manage lifetime of the cursor.
// DEPRECATED! Runs on the UI thread, OK for small/short queries.
getActivity().startManagingCursor(cursor);
//if (cursor.moveToLast()) {
// do {
// do what you need with the cursor here
// Setup mapping from cursor to view fields:
String[] fromFieldNames = new String[]
{DBAdapter.KEY_NAME,DBAdapter.KEY_PRICE,DBAdapter.KEY_LEVEL,DBAdapter.KEY_ART,DBAdapter.KEY_VALUETXT,DBAdapter.KEY_PIC };
int[] toViewIDs = new int[]
{R.id.tv_Shop_item1, R.id.tv_Shop_Price_item1,R.id.tv_shop_Level_item1,R.id.tv_shop_use_item1,R.id.tv_shop_use_item2,R.id.IV_Shop_item1 };
// Create adapter to may columns of the DB onto elemesnt in the UI.
SimpleCursorAdapter myCursorAdapter =
new SimpleCursorAdapter(
getActivity().getApplicationContext(), // Context
R.layout.item_shop, // Row layout template
cursor, // cursor (set of DB records to map)
fromFieldNames, // DB Column names
toViewIDs // View IDs to put information in
);
// Set the adapter for the list view
myList.setAdapter(myCursorAdapter);
// } while (cursor.moveToPrevious());
//}
}
或者有没有其他方法可以将图片添加到 ListView 中?因为我总是阅读其他问题如何保护 Chache 中的位图...
感谢您的帮助,并为我的英语不好感到抱歉。我来自德国;)
【问题讨论】:
-
你读过这个吗?基本上在后台线程中加载图像并缓存它们,然后在需要时使用它们。 developer.android.com/training/displaying-bitmaps/…
-
这对我的代码有用吗?
标签: android listview imageview lazy-evaluation