klondike (owner)

Revisions

gist: 190789 Download_button fork
public
Public Clone URL: git://gist.github.com/190789.git
Embed All Files: show embed
Custom Adapter using XML Layout #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
  }
 
}