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;
}
我知道getView()
对于要显示的集合的每个项目都会重复调用它。我正在使用的参考资料说,要优化性能,您应该重用视图。现在,这种“重用”让我感到困惑。
这些返回的视图将显示在ListView
. 如果我只返回一个View
用新数据重新填充的数据,如何正确显示数据?怎么会有多个条目?
换句话说,我不只是返回一个视图并期望看到多个ListView
条目吗?不应该是我返回新的Views
吗?