Android Programming Tutorials

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

return(createdAt);
}

TextView getStatus() {
if (status==null) {
status=(TextView)row.findViewById(R.id.status);
}

return(status);
}
}

Next, add a TimelineAdapter implementation that will display our timeline:


class TimelineAdapter extends ArrayAdapter<TimelineEntry> {
TimelineAdapter() {
super(Patchy.this, R.layout.row, timeline);
}

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

We need to have a TimelineAdapter as a private data member, so add one


(initialized to null), then instantiate the adapter in onCreate():


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

status=(EditText)findViewById(R.id.status);

191
Free download pdf