Skip to content

Instantly share code, notes, and snippets.

@konklone
Created September 22, 2009 03:32
Show Gist options
  • Save konklone/190789 to your computer and use it in GitHub Desktop.
Save konklone/190789 to your computer and use it in GitHub Desktop.
protected class TweetAdapter extends BaseAdapter {
private Activity context;
private Status[] tweets;
LayoutInflater inflater;
public TweetAdapter(Activity c, Status[] tw) {
context = c;
tweets = tw;
inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return tweets.length;
}
public Object getItem(int position) {
return tweets[position];
}
public long getItemId(int position) {
Status tweet = (Status) getItem(position);
return tweet.getId();
}
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout view;
if (convertView == null) {
view = (LinearLayout) inflater.inflate(R.layout.legislator_tweet, null);
} else {
view = (LinearLayout) convertView;
}
Status tweet = (Status) getItem(position);
TextView text = (TextView) view.findViewById(R.id.tweet_text);
text.setText(tweet.getText());
TextView when = (TextView) view.findViewById(R.id.tweet_when);
when.setText(tweet.getCreatedAt().toGMTString());
return view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment