试图从我的资产文件夹中更改我的字体,但我收到错误说"方法setTypeface(Typeface)未定义类型Object"

时间:2016-10-28 16:19:30

标签: android eclipse typeface

这是我的适配器文件,我在eclipse上收到错误。请帮帮我们:)这里是代码,你可以检查出来谢谢你们。这是我的适配器文件,我得到错误的日食。请帮帮我们:)这是代码,你可以检查出来谢谢你们。

private Activity activity;
private List<Pojo> itemsfavorite;
private Pojo objFavoriteBean;
private int row;


public Favorite_Activity_Adapter(Activity act, int resource, List<Pojo> arrayList) {
    super(act, resource, arrayList);
    this.activity = act;
    this.row = resource;
    this.itemsfavorite = arrayList;


}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;
    ViewHolder holder;
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(row, null);

        holder = new ViewHolder();
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    if ((itemsfavorite == null) || ((position + 1) > itemsfavorite.size()))
        return view;

    objFavoriteBean = itemsfavorite.get(position);



    holder.txt_favoquote=(TextView)view.findViewById(R.id.text_dis);
    holder.txt_favotitle=(TextView)view.findViewById(R.id.text_title);

//you can make any language quotes app just put ttf file in asset->font and below set ttf file

    String fontPathtitle = "font/Kremlin.ttf";
    Typeface tftitle = Typeface.createFromAsset(activity.getAssets(), fontPathtitle);
    holder.txt_categorylistquote).setTypeface(tftitle);
    holder.txt_title).setTypeface(tftitle);

    String formattedString=android.text.Html.fromHtml(objFavoriteBean.getPQuote().toString()).toString();
    holder.txt_favoquote.setText(formattedString);
    return view;

}

public class ViewHolder {


    public Object txt_title;
    public Object txt_categorylistquote;
    public  TextView txt_favoquote,txt_favotitle;

}

}

谢谢你们

1 个答案:

答案 0 :(得分:0)

String fontPathtitle = "font/Kremlin.ttf";
Typeface tftitle = Typeface.createFromAsset(activity.getAssets(), fontPathtitle);
holder.txt_categorylistquote).setTypeface(tftitle);
holder.txt_title).setTypeface(tftitle);

你确定没问题吗?我看到一个类型错误(额外&#34;)&#34; in:

 holder.txt_categorylistquote).setTypeface(tftitle);
 holder.txt_title).setTypeface(tftitle);

应该是:

 holder.txt_categorylistquote.setTypeface(tftitle);
 holder.txt_title.setTypeface(tftitle);

更重要的是txt_titletxt_categorylistquote应该是ViewHolder中的TextView,因为setTypeface()方法适用于Textviews

Android Documentation

中阅读更多内容