Reputation: 37
Hey my question is how can I speed up the loading of my listView...because I have the problem that it is realy lazy because of the ImageView. But how could I load the pictures in my cache? I'm using the simple cursor adapter to load the data from my Sql Database. Here is my code:
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());
//}
}
Or is there any other way to add the pictures to the ListView? Because I always read other Questions how to safe bitmaps in the Chache...
Thanks for helping and sorry for my bad englsih..Im from Germany;)
Upvotes: 0
Views: 276
Reputation: 89
Try this library. It's very solid and well featured image loading library with cache support.
https://github.com/nostra13/Android-Universal-Image-Loader
Upvotes: 1