【发布时间】:2018-04-29 20:28:07
【问题描述】:
我已经尝试了可以在 stackoverflow 上找到的所有方法,但似乎没有任何效果。
问题是我无法更改 CardViewLayout 中任何 TextView 的字体。
我尝试过字体系列,xml 中的文本外观 我已经通过这样做进行了更改,但我收到错误 无法解析符号'itemView'
代码:
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);
}
}
}
【问题讨论】:
-
itemView是在哪里声明的? -
我试图在公共 ViewHolder 中声明它,我得到了错误释放,但是当我启动应用程序时它崩溃了。
-
请edit您的问题包括您的尝试和完整的错误消息。
标签: java android xml android-layout android-viewholder