2011-06-10 82 views
0

我正在尝试使用“http://github.com/commonsguy/cwac-endless”为我的列表视图实现分页。Android:无尽的适配器问题

当我向下滚动到第一页的底部时,我正确地获得第一页结果,我看到了旋转轮,但没有得到任何结果。

我注意到从LogCat中,getPendingView(),cacheInBackground(),appendCachedData()和MyCustomAdapter的getView()被无限调用。

任何人都可以帮忙。

谢谢, nehatha。

这里是我的代码片段:

Activity{ 
    onCreate() { 
     myList = new ArrayList<Item>(); 
     setListAdapter(new DemoAdapter(myList)); 
     nextLink = "service_url"; //for first page results (say 1-25) 
    } 

    final Handler handler = new Handler() { 
     public void handleMessage(final Message msg) { 
      // 
      updateList(jsonResponse); 
     } 
    }; 

    updateList(String jsonString) { 
     //parse json 
     //add to `myList` 
     //update `nextLink`, if there is next page available 
    } 

    class DemoAdapter extends EndlessAdapter { 
     private RotateAnimation rotate=null; 

     DemoAdapter(List<Item> list) {   
      super(new MyCustomAdapter(LatestUpdatesList.this, R.layout.latest_update_item, list)); 
      //rotate code 
     } 

     @Override 
     protected boolean cacheInBackground() { 
      if(nextLink != null && nextLink.length() > 0){ 
       HttpHandler httpHandler = new HttpHandler(nextLink, "GET", handler); 
       Thread latestUpdatesThread = new Thread(httpHandler); 
       latestUpdatesThread.start(); 
       return true; 
      } 
      return false;   
     } 

     @Override 
     protected void appendCachedData() { 
      MyCustomAdapter adapter = (MyCustomAdapter)getWrappedAdapter(); 
      adapter.setList(myList); 

     } 
    } //DemoAdapter 

} //Activitiy 
+0

能否请你帮我在这EndlessAdapter为您的代码看起来类似于我的要求? – Korhan 2013-02-13 10:45:46

回答

0

我已经不是调用一个新的线程我的web服务(内cacheInBackground()方法)固定的问题。相反,我直接直接调用我的HttpHandler的get()方法。但我不确定这是最好的解决方案。

感谢, nehatha

+0

你能帮我解决这个EndlessAdapter吗,因为你的代码看起来和我的要求相似吗? – Korhan 2013-02-13 11:42:08