I try to implement homeline pagination via Twitter4j to pull-to-refresh list from Chris Banes. However, I have problems of that how to realize it. I have some notes how it should work but it isn't so, my pull refresh list doesn`t refresh. Have any ideas how to upload next 40 tweet to list on refresh?
Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tweetlist);
initializeVars();
paging = new Paging(1, 40);
try {
ListView actualListView = pullToRefreshView.getRefreshableView();
tweets = twitter.getHomeTimeline(paging);
tweetAdapter = new TweetListAdapter(this, R.layout.customtweetlist, tweets);
actualListView.setAdapter(tweetAdapter);
} catch (TwitterException e) {
e.printStackTrace();
}
}
public void onRefresh() {
new GetDataTask().execute();
}
private class GetDataTask extends AsyncTask<Void, Void, List<Status>> {
protected List<twitter4j.Status> doInBackground(Void... params) {
paging.setPage(2);
try {
tweets = twitter.getHomeTimeline(paging);
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tweets;
}
protected void onPostExecute(List<twitter4j.Status> result) {
tweetAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
pullToRefreshView.onRefreshComplete();
super.onPostExecute(result);
}
}
My TweetAdapter
public class TweetListAdapter extends ArrayAdapter<Status> {
private final Context context;
private final List<Status> values;
public TweetListAdapter(Context context,int textViewResourceId, List<Status> tweets) {
super(context, textViewResourceId, tweets);
this.context = context;
this.values = tweets;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.customtweetlist, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.tvText);
ImageView imageView = (ImageView) rowView.findViewById(R.id.ivImage);
Status tweet = values.get(position);
textView.setText(tweet.getText());
// imageView.setImageBitmap(getBitmap(tweet.getProfileImageUrl()));
rowView.invalidate();
return rowView;
}
public static Bitmap getBitmap(String bitmapUrl) {
try {
URL url = new URL(bitmapUrl);
return BitmapFactory.decodeStream(url.openConnection() .getInputStream());
}
catch(Exception ex) {return null;}
}
}