Custom ListView in Fragment not adhering to parent theme

前端 未结 2 1831
挽巷
挽巷 2020-12-18 08:57

I\'m currently having an issue with using custom ListView adapters with the Holo.Light theme. Within the activities and fragments, any TextViews are displayed in the theme\'

2条回答
  •  误落风尘
    2020-12-18 09:20

    You haven't posted any actual code, but since I've had exactly the same problem, I would guess that you are passing the wrong Context to your custom adapter constructor.

    I've been doing something like this (within my Fragment):

    dataSource = new MyCursorAdapter(getActivity().getApplicationContext(), R.layout.myrow, data,
                fields, new int[] { R.id.field1, R.id.field2 });
    

    All I had to do to fix the problem, was to replace getActivity().getApplicationContext() by getActivity():

    dataSource = new MyCursorAdapter(getActivity(), R.layout.myrow, data,
                fields, new int[] { R.id.field1, R.id.field2 });
    

    And it started to work as expected.

    MyCursorAdapter (extending SimpleCursorAdapter) constructor:

    public MyCursorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) { //... }
    

提交回复
热议问题