Android: problem with endless adapter
I'm trying to use "http://github.com/commonsguy/cwac-endless" to implement pagination for my list views.
I'm getting the first page results correctly, when I scrolled down to the bottom of the 1st page, i'm seeing the spinning wheel but im not getting any results.
I noticed from the LogCat that, getPendingView(), cacheInBackground(), appendCachedData() and MyCustomAdapter's getView() are getting called infinately.
Can an开发者_C百科ybody plz help.
Thanks, nehatha.
Here is my code snippet:
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
I have fixed the issue by not calling my web service in a new thread (inside cacheInBackground() method). Instead i'm directly calling my HttpHandler's get() method directly. But I'm not sure this is the best fix.
Thanks, nehatha
精彩评论