简体   繁体   中英

How to set Font of List View Items to Marathi

I'm using list view in my app, I want to the font of list view item in marathi, but certain error occurs and app get close. Here is my code:

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

    View vi=convertView;
    ViewHolder holder;

    if(convertView==null){ 

        /********** Inflate tabitem.xml file for each row ( Defined below ) ************/
        vi = inflater.inflate(R.layout.tabitem, null); 

        /******** View Holder Object to contain tabitem.xml file elements ************/

        holder=new ViewHolder();
        holder.text.setTypeface(Typeface.createFromAsset(vi.getContext().getAssets(), "akshar.ttf"));
        holder.text1.setTypeface(Typeface.createFromAsset(vi.getContext().getAssets(), "akshar.ttf"));
        holder.text=(TextView)vi.findViewById(R.id.text);
        holder.text1=(TextView)vi.findViewById(R.id.text1);
        holder.image=(ImageView)vi.findViewById(R.id.image);

       /************  Set holder with LayoutInflater ************/
        vi.setTag(holder);
    }

The code you have pasted above is the Adapter class code, then just change

holder.text.setTypeface(Typeface.createFromAsset(vi.getContext().getAssets(), "akshar.ttf"));
    holder.text1.setTypeface(Typeface.createFromAsset(vi.getContext().getAssets(), "akshar.ttf"));

lines to ..

holder.text.setTypeface(Typeface.createFromAsset(context.getAssets(), "akshar.ttf"));
        holder.text1.setTypeface(Typeface.createFromAsset(context.getAssets(), "akshar.ttf"));

where

"context" is the Activity class context which you passing in this adapter class. if still your issue is unsolved then paste ur full code i'll definitely help you..Happy coding.

使用“ fonts / akshar.ttf”而不是“ akshar.ttf”。

First download the font file by going to Click here to download.

Then in your project assets folder paste Roupya.ttf file. in your main activity write Typeface typeface = Typeface.createFromAsset(getAssets(), "Roupya.ttf");

and then yourTextView.setTypeface(typeface); this will work fine... I've checked then posting this answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM