I want to add custom font to the button (LetterBtn) in my Adapter that extends BaseAdapter, but I get an error with getAssets() as "cannot resolve method 'getAssets()'".
The font is in the assets/fonts/ folder, it works fine in my other Activity.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Button letterBtn;
if (convertView == null) {
letterBtn = (Button)letterInf.inflate(R.layout.letter, parent, false);
} else {
letterBtn = (Button)convertView;
}
letterBtn.setText(letters[position]);
Typeface font1 = Typeface.createFromAsset(getAssets(),
"fonts/nexalight.otf");
letterBtn.setTypeface(font1);
return letterBtn;
}
I think you are facing this problem in your Adapter
class. Update your Adapter
class as below:
....................
................................
public class YourAdapter extends ......
{
.........
..............
Typeface font;
public YourAdapter(Context context, ...........)
{
super(context, ..........);
font = Typeface.createFromAsset(context.getAssets(), "fonts/nexalight.otf");
}
...............
........................
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = letterInf.inflate(R.layout.letter, parent, false);
}
Button letterBtn = (Button ) convertView.findViewById(R.id.YOUR_BUTTON_ID);
letterBtn.setText(letters[position]);
letterBtn.setTypeface(font);
return convertView;
}
...................
.........................
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With