Android Programming Tutorials

(Romina) #1
No, Really Listening To Your Friends

class TimelineEntry {
String friend="";
String createdAt="";
String status="";

TimelineEntry(String friend, String createdAt,
String status) {
this.friend=friend;
this.createdAt=createdAt;
this.status=status;
}
}

Now, add an ArrayList of TimelineEntry objects to serve as the timeline


itself, as a private data member of Patchy:


private List<TimelineEntry> timeline=new ArrayList<TimelineEntry>();

Then, add a TimelineEntryWrapper that will update one of our rows with the


contents of a TimelineEntry:


class TimelineEntryWrapper {
private TextView friend=null;
private TextView createdAt=null;
private TextView status=null;
private View row=null;

TimelineEntryWrapper(View row) {
this.row=row;
}

void populateFrom(TimelineEntry s) {
getFriend().setText(s.friend);
getCreatedAt().setText(s.createdAt);
getStatus().setText(s.status);
}

TextView getFriend() {
if (friend==null) {
friend=(TextView)row.findViewById(R.id.friend);
}

return(friend);
}

TextView getCreatedAt() {
if (createdAt==null) {
createdAt=(TextView)row.findViewById(R.id.created_at);
}

190
Free download pdf