public View getView(int index, View view, ViewGroup parent){
if (view == null) { // for the first time, inflate the view
LayoutInflater inflater =
LayoutInflater.from(parent.getContext());
view = inflater.inflate(
R.layout.time_list_item, parent, false);
}
/**
* The layout under consideration has two TextViews in it
* one to display the time and other to display some text.
*/
TimeRecord time = times.get(index);
timeTextView.setText(time.getTime());
TextView timeTextView = (TextView)
view.findViewById(R.id.time_view);
notesTextView.setText(time.getNotes());
TextView notesTextView = (TextView)
view.findViewById(R.id.notes_view);
return view;
}
I know that getView()
is called repeatedly for every item of the collection that is to be displayed. The reference I am using says that to optimize performance, you should just reuse the view. Now, this 'reuse' is confusing me.
These returned views will be displayed in the ListView
. If I ever only return one View
that I re-populate with new data, how will the data be properly displayed ? How can there be multiple entries ?
In other words, am I not just returning a single view and expecting to see multiple ListView
entries ? Shouldn't it be that I return new Views
?