【问题标题】:How could I speed up the loading of a ImageView in listView while using SimpleCursorAdapter?如何在使用 SimpleCursorAdapter 时加快 listView 中 ImageView 的加载速度?
【发布时间】: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 中的位图...

感谢您的帮助,并为我的英语不好感到抱歉。我来自德国;)

【问题讨论】:

标签: android listview imageview lazy-evaluation


【解决方案1】:

试试这个库。它是非常可靠且功能强大的图像加载库,支持缓存。

https://github.com/nostra13/Android-Universal-Image-Loader

【讨论】:

  • 但是这张图片在我的drawable文件夹中是个问题
  • 如何将图片添加到我的 ListView 中?
  • 您还可以使用库加载可绘制文件夹中的图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-20
  • 1970-01-01
  • 2012-09-27
  • 1970-01-01
  • 2012-05-06
  • 1970-01-01
相关资源
最近更新 更多