Any idea why this crashes on open? I am getting no errors now. I have read through the tutorial again and cannot see why my implementation is crashing.
Even with the OnItemClickListener() taken out it still crashes, I am lost for what the error is.
public class findFragment extends Fragment implements AdapterView.OnItemClickListener{
ListView list;
List<RowItem> rowItems;
public static final String[] titles = new String[] { "Strawberry",
"Banana", "Orange", "Mixed" };
public static final String[] descriptions = new String[] {
"It is an aggregate accessory fruit",
"It is the largest herbaceous flowering plant", "Citrus Fruit",
"Mixed Fruits" };
public static final Integer[] images = { R.drawable.test,
R.drawable.test, R.drawable.test, R.drawable.test };
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.find, container, false);
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem(images[i], titles[i], descriptions[i]);
rowItems.add(item);
}
list = (ListView) view.findViewById(R.id.list);
CustomListViewAdapter adapter = new CustomListViewAdapter(getActivity(),
R.layout.imglist, rowItems);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
return view;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
list.setItemChecked(position, true);
}
Use
CustomListViewAdapter adapter = new CustomListViewAdapter(getActivity(),
R.layout.imglist, rowItems);
getActivity()
returns the activity this fragment is associated with. You need activity context not this
Edit:
public class findFragment extends Fragment implements OnItemClickListener{
You need to override onItemClick
Keep
list.setOnItemClickListener(this);