Android Programming Tutorials

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

public View getView(int position, View convertView,
ViewGroup parent) {
View row=convertView;
TimelineEntryWrapper wrapper=null;


if (row==null) {
LayoutInflater inflater=getLayoutInflater();


row=inflater.inflate(R.layout.row, parent, false);
wrapper=new TimelineEntryWrapper(row);
row.setTag(wrapper);
}
else {
wrapper=(TimelineEntryWrapper)row.getTag();
}


wrapper.populateFrom(timeline.get(position));


return(row);
}
}


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);
}


return(createdAt);
}


197
Free download pdf