I have problem with setting up own font for my ListView, I don’t know how to use own Adapter class and what xml do I need (besides that one in which I put ListView). I’m hoping (in ListView) just for centered text with own font.
Thats my Adapter:
public class MyAdapter extends BaseAdapter {
private String[] objects; // no objects just String array
private final Context context;
public MyAdapter(Context context, String[] objects) {
this.context = context;
this.objects = objects;
}
@Override
public int getCount() {
return objects.length;
}
@Override
public Object getItem(int position) {
return objects[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Object obj = objects[position];
TextView tv = new TextView(context);
tv.setText(obj.toString());
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/kolejRogFont.ttf");
tv.setTypeface(tf);
return tv;
}
}
and it’s calling in Lista.java
ListView lv = new ListView(this);
lv.setAdapter(new MyAdapter(this, listview_array));
Codes are from another topic on StackOverFlow.
-
I get an error on line (undefined method):
Typeface tf = Typeface.createFromAsset(getAssets(),”fonts/kolejRogFont.ttf”);
2.Nothings appear on the screen. Should I make a XML for ListView Layout? What should it contain?
Change MyAdapter Code as: