A
A
Anton2016-03-31 22:46:12
Java
Anton, 2016-03-31 22:46:12

Why does it refer to TextView and how to fix it?

Implemented the list. Everything worked.
I wanted to add a preview and then I got an error:
3acb072a03724e84b34362e0b66eb7a3.png
Fragment code:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder = null;

    if (convertView == null) {

        LayoutInflater vi = (LayoutInflater)getSystemService( Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.person_info, null);

        holder = new ViewHolder();
        holder.name = (TextView) convertView.findViewById(R.id.name);

        holder.preview = (ImageView) convertView.findViewById(R.id.preview);    //  Error

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    Persons person = personsList.get(position);
    holder.name.setText(person.getName());
    holder.tracks.setText(person.getTracks());
    holder.albums.setText(person.getAlbums());
    holder.genres.setText(person.getGenres());
    //  holder.preview.setText(person.getGenres());     //  The temporary line

    return convertView;
}

Googling did not find anything sensible - some other methods of implementation.
In general, help, please, kind people.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis Zagaevsky, 2016-03-31
@hummingbird

Apparently, you declared the preview as a TextView in the holder, but it should be as an ImageView. Apparently.

M
Maxim, 2016-03-31
@Bublik

what is holder.preview for you?
In the view you have R.id.preview as described?

T
Tiberal, 2016-03-31
@Tiberal

The type in the holder does not match the type of the assigned view. Preview is your text view

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question