2013-10-03 35 views
1

我有拉到刷新https://github.com/chrisbanes/Android-PullToRefresh在此链接中给出。一切正常。但是当我的列表项完成后,加载图标和拉动刷新标签仍然可见。那么,如何在列表结束时禁用滚动?禁用加载拉来刷新列表视图

mainListView.setOnRefreshListener(new OnRefreshListener() { 

       @Override 
       public void onRefresh(PullToRefreshBase refreshView) { 

             String total_bk_count = subCategory             .getTotal_Book_Count(); 
             count_of_book = Integer.parseInt(total_bk_count); 
             listCountt = mainbooksAdpater.getCount(); 
             Log.e("StroreActivity","Total book count---====----====---+"+count_of_book); 
             Log.e("StroreActivity","list Count---====----====---+"+listCountt); 
             if(listCountt < count_of_book) 
             { 

              int bookCount = Common.getBookCountNumber(); 
              Common.setBookCount(bookCount+1); 
              String refresh_Pull_Url = Common.getUrlForeCategoryBooks(id, Common.NUMBER_OF_BOOKS_PER_REQUEST); 
              Log.e("Rathis to Check url", Common.getUrlForeCategoryBooks(id, Common.NUMBER_OF_BOOKS_PER_REQUEST)); 
              PulltoRefreshAsync onCatBooksTaskScroll = new PulltoRefreshAsync(Common.getUrlForeCategoryBooks(id, Common.NUMBER_OF_BOOKS_PER_REQUEST)); 
              onCatBooksTaskScroll.execute(); 

             Log.e("StroreActivity","Total Book count::" + book_count_no); 

            } 
             else 
             { 

             mainListView.setMode(Mode.DISABLED);  
             Toast.makeText(getApplicationContext(), "end of list", Toast.LENGTH_SHORT).show(); 

             } 
            } 
           }); 

的AsyncTask类:

public class PulltoRefreshAsync extends AsyncTask<Object,Object,Object> { 
    int refreshCount; 
    String refresh_URL; 
    public PulltoRefreshAsync(String url) { 
     refresh_URL = url; 

    } 

    /* 
    * PulltoRefreshAsync(int i) { refreshCount = i; } 
    */ 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     Log.e("Checking Purpose", refresh_URL); 




    } 

    @Override 
    protected String doInBackground(Object... arg0) { 
     JsonParserRefresh jp = new JsonParserRefresh(); 
     Log.e("StroreActivity","Array to String::" + refresh_URL); 
     String jsonString = jp.getJSONFromURL(refresh_URL); 
     Log.e("StroreActivity","JsonString::" + jsonString); 
     jsonParseForCategoryBooksGridScroll(jsonString); 
     return null; 
    } 

    @Override 
    protected void onPostExecute(Object result) { 
     super.onPostExecute(result); 
     /* 
     * if(mProgressDialog.isShowing()) { mProgressDialog.dismiss(); } 
     */ 

     final MainBooksAdapter mainbooksAdpater = new MainBooksAdapter(
       StoreActivity.this, R.layout.aa, mainBooksList); 
     final int old_pos = mainListView.getRefreshableView() 
       .getFirstVisiblePosition() + 1; 
     mainListView.setAdapter(mainbooksAdpater); 

     tvvisiblebookCount.setText("" + mainbooksAdpater.getCount()); 

     /*if(listCountt < count_of_book) 
     { 

      mainListView.setMode(Mode.DISABLED);*/ 
     mainListView.post(new Runnable() { 

      @Override 
      public void run() { 
       mainListView.onRefreshComplete(); 
       mainListView.getRefreshableView().setSelection(old_pos); 
      } 
     }); 
     //} 
     mainbooksAdpater.notifyDataSetChanged(); 

    } 



} 

回答

5

对于谁可能有similat问题的其他人:

你没有实现它这样

mainListView.post(new Runnable() { 

      @Override 
      public void run() { 
       mainListView.onRefreshComplete(); 
       mainListView.getRefreshableView().setSelection(old_pos); 
      } 
     }); 

,而不是仅仅做像这样:

mainListView.onRefreshComplete(); 

我还注意到了一件事情,它不是保存旧的pos值来回到它,为什么不使用notifyDataSetChanged它保持列表的位置,只是尽量不要重新列出你的列表,即:mainBooksList = ...,而是试试这个:

mainBooksList.clear(); 
mainBooksList.addAll(YOUR DATA); 
adapter.notifyDataSetChanged(); 

瞧!

希望这可以帮助别人