Search code examples
androidandroid-arrayadaptertypeface

Set custom typeface for arrayadapter


Here's my code:

String[] filled_arr;
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.list_item, R.id.tv_wi, filled_arr);
listview.setAdapter(adapter);

and here's the typeface:

final Typeface typeface = Typeface.createFromAsset(getAssets(), "Constantia.ttf");

How can I set it for the adapter?


Solution

  • I've already solved the problem by overriding the array adapter. Hope, it'll help someone else)

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
                android.R.layout.simple_list_item_1, filled_arr) {
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View view = super.getView(position, convertView, parent);
                TextView text = (TextView) view.findViewById(android.R.id.text1);
                text.setTypeface(typeface);
                return view;
            }
        };