ListView にロードしたい約 12000 レコードのデータベースがあります。BaseAdapter を使用しています。ListView で項目を読み込むと、時間がかかりすぎます。
この時間を短縮する方法はありますか。たとえば、スクロール バーが ListView の最後に到達するまで限られた数のアイテムのみをロードし、その後さらに多くのアイテムをロードするアプリを見たことがあります。
8043 次
2 に答える
1
これは便利かもしれません.load ListView
Moreボタンがあります:
http://www.androidhive.info/2012/03/android-listview-with-load-more-button/
こちらもご覧ください:
于 2013-07-26T20:14:13.757 に答える
0
リストに onScrollListener を設定し、アイテムの可視性とオフセットを追跡する必要があります。ここで例を示します。
// Adapter for the custom list
adapter = new Adapter(this, activityList);
setListAdapter(adapter);
registerForContextMenu(getListView());
getListView().setOnScrollListener(new OnScrollListener(){
public void onScroll(AbsListView lw, final int firstVisibleItem,
final int visibleItemCount, final int totalItemCount) {
switch(lw.getId()) {
case android.R.id.list:
// Make your calculation stuff here. You have all your
// needed info from the parameters of this function.
// Sample calculation to determine if the last
// item is fully visible.
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCount) {
// Last item is fully visible.
Log.i("a", "last item fully visible...");
try {
if(offset > 0){
int newLimit;
int oldOffset = offset;
if(offset >= limit){
newLimit = limit;
offset = offset - limit;
}
else{
newLimit = length;
offset = 0;
}
for (int i=0; i < newLimit; i++)
{
JSONObject item = jFeed.getJSONObject(i + length - oldOffset);
// Pulling items from the array
// Get list info
String sInfo = item.getString(TAG_INFO);
Log.i(MainActivity.class.getName(), "Info: " + sInfo);
// Populate the dynamic custom list
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_INFO, sInfo);
activityList.add(map);
}
adapter.notifyDataSetChanged();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
if(scrollState == 0)
Log.i("a", "scrolling stopped...");
}
});
于 2013-07-26T20:33:23.787 に答える