Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change font of list fragment on Detail fragment

I am trying to implement fragment using android 4.0. I have added the three items in list fragment in my DummyContent.java file

static {
    // Add 3 sample items.
    addItem(new DummyItem("1", "Videos"));
    addItem(new DummyItem("2", "Images"));
    addItem(new DummyItem("3", "Story"));
}

These Videos,Images,Story are appearing on left side of fragment on click of each it item shows details information on detail fragment in right hand side.

I want to change the font of these list views but problem is list fragment uses systems textview as below

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // TODO: replace with a real list adapter.
    setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
            android.R.layout.simple_list_item_activated_1,
            android.R.id.text1, DummyContent.ITEMS));
}

Which is not allowing me to apply Typeface to android.R.id.text1

Please help me

like image 338
Hemantwagh07 Avatar asked Jan 15 '23 14:01

Hemantwagh07


1 Answers

One way to is to extend ArrayAdapter and override the getView method to get a hold of the TextView:

public class MyArrayAdapter<T> extends ArrayAdapter<T> {

    public MyArrayAdapter(Context context, List<T> items) {

        super(context, android.R.layout.simple_list_item_activated_1, android.R.id.text1, items);
    }

    public MyArrayAdapter(Context context, T[] items) {

        super(context, android.R.layout.simple_list_item_activated_1, android.R.id.text1, items);
    }

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

        View view = super.getView(position, convertView, parent);
        TextView textView = (TextView) view.findViewById(android.R.id.text1);
        textView.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "font/segoeuil.tff"));

        return view;
    }
}

You would then set your adapter like so:

setListAdapter(new MyArrayAdapter<DummyContent.DummyItem>(getActivity(), DummyContent.ITEMS);
like image 74
Jason Robinson Avatar answered Jan 17 '23 05:01

Jason Robinson