Listing 9.19 getView and getItem()


#1

When I implement the code in Listing 9.19 (below) I get two, I’m pretty sure related, errors:
At the @Override I get: the method getView must override or implement a supertype method.

and at the getItem(position) line I get: the method getItem is undefined for the type CrimeListFragment

But aren’t both getView and getItem abstracts in ArrayAdapter? I checked and I have: import android.widget.ArrayAdapter;

Any idea how to get this resolved?

Thanks

@Override
public View getView (int position, View convertView, ViewGroup parent) {
// if we werent given a view, inflate one
if (convertView == null) {
convertView = getActivity().getLayoutInflater()
.inflate(R.layout.list_item_crime, null);
} // end if

// Configure the view for this Crime
Crime c = getItem(position);  // given the item's position, get the Crime

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;

} // end getview


#2

My own error. I had placed the code in the wrong place in CrimeListFragment. I erroroneously placed it after CrimeAdapter was defined, instead of within its scope.
Once I move the right } the error disappeared.