[英]Android dynamic listview from sqlite
我有一個從SQLite數據庫填充的ListView。 數據庫有300,000多行,並且從不同的內容(例如,姓名,姓氏,年齡和其他常規數據庫內容)搜索之后,將填充列表視圖。
它對於少量的搜索返回效果很好,但是如果搜索返回的結果超過2,000,則該應用程序將凍結並停止。
我想做的是從數據庫中返回100個結果,然后當它滾動到列表的底部時,它又返回到游標並再加載100個。我有一個動態列表,但是它仍然凍結,因為它仍在搜索獲得1000多個結果,僅顯示100個結果。 這是一些偽代碼(由於listview是500多個行,因此取決於搜索內容有很多if else語句)
public class example extends Activity implements OnScrollListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showlist);
//It opens database here
ListView list = (ListView) findViewById(R.id.listView1);
if(nameOnly is searched){
//adds data to list with array adapter here
//return 100 results and put it in a list
}else if(name and surname is searched){
//adds data to list with array adapter here
//return 100 results and put it in a list
}else if (surname only searced){
//adds data to list with array adapter here
//return 100 results and put it in a list
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
boolean load = firstVisibleItem+visibleItemCount>=totalItemCount;
if(load){
//This is where i want to set it to return
//the next 100 and add it to the list from the if else statements
}
}
@Override
public void onScrollStateChanged(AbsListView arg0, int arg1) {
}
}
所以我想嘗試再次在OnScroll中將光標移到SQLite游標中並使用OFFSET,但這沒有用。 我現在不是這是否是最好的方法,所以任何想法都值得贊賞!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.