lundi 22 juin 2015

Problems implementing ViewHolder pattern

I'm working on an android app from a book. I'm getting errors : "crimeHolder cannot be resolved" and I can't understand why..

 public View getView(int poisition, 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);
                ViewHolder crimeHolder = new ViewHolder();
                crimeHolder.titleTextView = (TextView)convertView.findViewById(R.id.listItemTitleTextView);
                crimeHolder.dateTextView = (TextView)convertView.findViewById(R.id.listItemDateTextView);
                crimeHolder.solvedCheckBox = (CheckBox)convertView.findViewById(R.id.crimeListItemSolvedCheckBox);

                // store the holder with the view
                convertView.setTag(crimeHolder);
            }

            //Configure the view for this Crime
            Crime crime = getItem(poisition);

            if (crime!=null)
            {

These 3 show the errors :

                crimeHolder.titleTextView.setText(crime.getTitle());
                crimeHolder.dateTextView.setText(crime.getDate().toString());   
                crimeHolder.solvedCheckBox.setChecked(crime.isSolved());
            }
            return convertView;

        }
    }

    static class ViewHolder
    {
        TextView titleTextView;
        TextView dateTextView;
        CheckBox solvedCheckBox;
    }

Aucun commentaire:

Enregistrer un commentaire