问题描述
我在SQLite表约4K行,表中有7列。
I have about 4k rows in sqlite table, table has 7 columns.
我创建工作的ListView用我自己的CursorAdapter。
I created working ListView with my own CursorAdapter.
查询是这样的 SELECT * FROM [表] ORDER BY [专栏] DESC;
表具有第一列 _id INTEGER PRIMARY KEY
,但顺序由另一列完成。
Table has first column _id INTEGER PRIMARY KEY
but ordering is done by another column.
有关使用我自己的 SQLiteOpenHelper
创建光标
mySQLiteOpenHelper pm = new mySQLiteOpenHelper();
SQLiteDatabase db = pm.getReadableDatabase();
Cursor c = db.query([tablename], new String[]{"_id", "[column]", "[column]", "[column]", "[column]", "[column]"}, null, null, null, null, "name ASC");
将它传递给的ListView
Passing it to ListView
ListView lv = (ListView) findViewById(R.id.list_items);
lv.setOnItemClickListener(this);
pa = new ItemsAdapter(ItemsActivity.this, c);
在ItemsAdapter我已经重新实现
In ItemsAdapter I have reimplemented
private LayoutInflater inflater;
@Override
public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
return inflater.inflate(R.layout.items_row, arg2,false);
}
和
@Override
public void bindView(View rtn, Context arg1, Cursor c) {
item_name = (TextView) rtn.findViewById(R.id.item_name);
item_description = (TextView) rtn.findViewById(R.id.item_description);
item_catalog_id = (TextView) rtn.findViewById(R.id.item_catalog_id);
item_true_price = (TextView) rtn.findViewById(R.id.item_true_price);
item_display_price = (TextView) rtn.findViewById(R.id.item_display_price);
item_button = (Button) rtn.findViewById(R.id.item_button);
item = new MyWrapClass(c);
// some work with item to fill up all UI items
}
MyWrapClass
MyWrapClass
public final class MyWrapClass {
public String name = "";
public String notes = "";
public int id = 0;
public String catalogId = "";
public int price = 0;
public int publicPrice = 0;
public String groupPrice = "";
public int order_count = 0;
public MyWrapClass(Cursor c) {
try {
id = c.getInt(0);
catalogId = c.getString(1);
name = c.getString(2);
price = c.getInt(3);
publicPrice = c.getInt(4);
groupPrice = c.getString(5);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
在同一行的init code的ListView中使用,并且它的工作非常好。
The same row init code was used in ListView and there it worked very good.
所以,如果你可以从这个code说,没有任何理由,为什么要加载第6行项目(一个屏幕高度),并滚动刷新(当您滚动一个项目下来的意思)需要1分钟的时间?
So if you can say from this code, is there ANY reason, why should load of 6 row items (one screen height) and scroll refresh (mean when you scroll one item down) take up to 1 minute?
的ListView只加载最多需要2分钟,然后大约有一半的时间来滚动一个列表项下/上。在哪里可以是性能问题?
Just load of ListView takes up to 2 minutes, and then about half time to scroll one list item down/up. Where can be the performance issue?
推荐答案
我想创建一个自定义的适配器
,只无论是需要积极的意见和负载重用在 getView()
法的意见。这真的很简单。
I'd create a custom Adapter
, that only loads whatever is needed for the active views and that reuses views in the getView()
method. It's really quite simple.
更新
我发现了一个很好的例子,你应该能够使用:
I found an excellent example, that you should be able to use:http://android.amberfog.com/?p=296
这篇关于与ListView和CursorAdapter的对于大数据量的性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!