-1

I've tried everything that I could find on stackoverflow but nothing seems to work.

The problem is that I cant change the font of any TextView inside my CardViewLayout.

I've tried font family, text appearance in xml I've changed it by doing this, but I'm getting the error Cannot resolve symbol 'itemView'

code:

public class cardAdapter extends ArrayAdapter<cardModel> {

public cardAdapter(Context context) {
    super(context, 0);
}

@Override
public View getView(int position, View contentView, ViewGroup parent) {
    ViewHolder holder;

    if (contentView == null) {
        LayoutInflater inflater = LayoutInflater.from(getContext());
        contentView = inflater.inflate(R.layout.card_layout, parent, false);
        holder = new ViewHolder(contentView);
        contentView.setTag(holder);
    } else {
        holder = (ViewHolder) contentView.getTag();
    }

    cardModel spot = getItem(position);

    holder.title.setText(spot.title);
    holder.description.setText(spot.description);
    Glide.with(getContext()).load(spot.url).into(holder.image);

    return contentView;
}

private static class ViewHolder {

    public TextView title;
    public TextView description;
    public ImageView image;

    Typeface customTypeOne = Typeface.createFromAsset(itemView.getContext().getAssets(), "fonts/typefaceone.ttf");

    public ViewHolder(View view) {
        this.title = (TextView) view.findViewById(R.id.title);
        title.setTypeface(customTypeOne);
        this.description = (TextView) view.findViewById(R.id.description);
        this.image = (ImageView) view.findViewById(R.id.image);
        }
    }
}
newbieCoder.pkg
  • 277
  • 2
  • 14

1 Answers1

0

but I'm getting the error Cannot resolve symbol 'itemView'

That is because you do not have anything named itemView.

First, replace:

Typeface customTypeOne = Typeface.createFromAsset(itemView.getContext().getAssets(), "fonts/typefaceone.ttf");

with:

Typeface customTypeOne;

Then, in your ViewHolder constructor, at the bottom, add:

customTypeOne = Typeface.createFromAsset(this.title.getContext().getAssets(), "fonts/typefaceone.ttf");

Now you are calling getContext() on something that exists.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I was just about to edit the code in the question, I've done that already, however when I launch the activity, it crashes – newbieCoder.pkg Apr 29 '18 at 20:36
  • @newbieCoder.pkg: Then use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Apr 29 '18 at 20:37
  • Hmm guess the error is that the font asset is not found. That makes it easy then :). Thanks a lot man. – newbieCoder.pkg Apr 29 '18 at 20:42