2013-07-26 1 views
1

ListView에서로드 할 약 12000 개의 레코드가있는 데이터베이스가 있습니다. BaseAdapter를 사용하고 있습니다. ListView에서 항목을로드하면 너무 오래 걸립니다.
스크롤 막대가 ListView 끝에 도달 할 때까지 제한된 수의 항목 만로드하는 응용 프로그램을 본 다음 더 많은 항목을 다시로드하는 등의 방법으로이 시간을 줄일 수 있습니까?큰 목록보기에서 데이터베이스로드

+0

세트 쿼리에서 한계 당신이 말했듯을 http://stackoverflow.com/questions/1407442/android-sqlite-and-huge-data-sets – tyczj

답변

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..."); 
    } 
}); 
관련 문제