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
か?