我想从我已经完成的SQLite数据库中实现List-View。但是现在我想在列表视图上实现分页setOnScrollListener。第一次我显示前50条记录之后我在列表末尾滚动时运行进度条一定数量的秒然后停止进度条另外50条记录附加到列表。我在列表视图分页上工作5天后我正在尝试很多时间,但它没有正常工作。可以帮助我解决这个问题。
这是我的代码。
listView.addFooterView(footer);
// Implementing scroll refresh
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
@Override
public void onScroll(AbsListView absListView, int firstItem, int visibleItemCount, final int totalItems) {
//Log.e("Get position", "--firstItem:" + firstItem + " visibleItemCount:" + visibleItemCount + " totalItems:" + totalItems + " pageCount:" + pageCount);
int total = firstItem + visibleItemCount;
Log.e("", "onScroll LocalPages=" + LocalPages);
// Total array list i have so it
if (pageCount < LocalPages) {
if (total == totalItems) {
// Execute some code after 8 seconds have passed
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
listView.addFooterView(footer);
OFFSET = pageCount * 50 ;
//Log.e("","After OFFSET pageCount =" + pageCount + " OFFSET value ="+OFFSET);
List<All_Post> allDesc = dbhelper.getAllDescriptions(OFFSET);
for (All_Post all_Post : allDesc)
{
descArray.add(all_Post);
}
if(adapter != null)
{
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
listView.setSelection(totalItems);
pageCount += 1;
Log.e(""," pageCount =" + pageCount + " LocalPages="+LocalPages);
}
}
}, 2000);
}
} else {
Log.e("hide footer", "footer hide");
listView.removeFooterView(footer);
}
}
});
答案 0 :(得分:0)
您可以按照以下方法执行此操作。
// create one final list
final ArrayList<String> temp = new ArrayList<String>();
temp.addAll(previous_data);
// call fxn for getting new value
// call your database query
// add new data into list
temp.addAll(new_Data);
// intailize static list of adapter showing data
// add data into list.
ActivityName.MainList = temp;
mAdapter.notifyDataSetChanged();
还有你的代码......谢谢