本例中 getView (int position, View convertView, ViewGroup parent) 中的 convertView 是如何变化的
how convertView change in getView (int position, View convertView, ViewGroup parent) in this example
能否请您为我解释一下 convertView
在此示例中将如何更改:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// If we weren't given a view, inflate one
if (convertView == null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null);
}
// Configure the view for this Crime
Crime c = getItem(position);
TextView titleTextView =
(TextView)convertView.findViewById(R.id.crime_list_item_titleTextView);
titleTextView.setText(c.getTitle());
TextView dateTextView =
(TextView)convertView.findViewById(R.id.crime_list_item_dateTextView);
dateTextView.setText(c.getDate().toString());
CheckBox solvedCheckBox =
(CheckBox)convertView.findViewById(R.id.crime_list_item_solvedCheckBox);
solvedCheckBox.setChecked(c.isSolved());
return convertView;
}
我想知道 titleTextView
& dataTextView
& solvedCheckBox
对 convertView 的影响???
或者在方法末尾返回的 convertView
与 convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null);
相同,并且 titleTextView
& dataTextView
& solvedCheckBox
不会更改 [=11 中的任何内容=]???
if (convertView == null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null);
}
这是convertView的初始化你只需要第一次做然后第二次就不需要而且titleTextView & dataTextView & solvedCheckBox不影响convertView
能否请您为我解释一下 convertView
在此示例中将如何更改:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// If we weren't given a view, inflate one
if (convertView == null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null);
}
// Configure the view for this Crime
Crime c = getItem(position);
TextView titleTextView =
(TextView)convertView.findViewById(R.id.crime_list_item_titleTextView);
titleTextView.setText(c.getTitle());
TextView dateTextView =
(TextView)convertView.findViewById(R.id.crime_list_item_dateTextView);
dateTextView.setText(c.getDate().toString());
CheckBox solvedCheckBox =
(CheckBox)convertView.findViewById(R.id.crime_list_item_solvedCheckBox);
solvedCheckBox.setChecked(c.isSolved());
return convertView;
}
我想知道 titleTextView
& dataTextView
& solvedCheckBox
对 convertView 的影响???
或者在方法末尾返回的 convertView
与 convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null);
相同,并且 titleTextView
& dataTextView
& solvedCheckBox
不会更改 [=11 中的任何内容=]???
if (convertView == null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null);
}
这是convertView的初始化你只需要第一次做然后第二次就不需要而且titleTextView & dataTextView & solvedCheckBox不影响convertView