I have a listview (which has a textview in its items) and a button in my activity. And I'm loading the data into listview using loaders mechanism. And I'm starting settings activity of app on click of the button. User can change font type and size in settings screen. And I'm getting changed font values from preferences and setting it to textviews inside bindView() method of my custom adapter class. But I'm able to see the changed font in listview only when I start the activity again. How can I apply changed font size and type to listview items as soon as user clicks back button from settings screen? How can I refresh my listview for only to change the font? Please guide me.

I have tried the below to refresh the listview but it was of no use as it notifies only when the adapter dataset is changed.

@Override
public void onResume() {
    super.onResume();
    adapter.notifyDataSetChanged();
 } 
有帮助吗?

解决方案

Call this method after changing font. In this paramter "v" is your listview or listview parentand "f" is your font in method.

    /**
 * To apply custom font for whole activity
 */
public static void applyFontForWholeActivity(final View v) {
    // Typeface fontToSet = Typeface.createFromAsset(v.getContext()
    // .getAssets(), "fonts/EUROSTILE_BOLD.TTF");

    try {
        if (v instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) v;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View child = vg.getChildAt(i);
                applyFontForWholeActivity(child);
            }
        } else if (v instanceof TextView) {
            TextView tv = (TextView) v;
            tv.setTypeface(ActivityUtils.fontToSetGlobal);
        }
    } catch (Exception e) {
        e.printStackTrace();
        // ignore
    }
}

其他提示

Set your adapater again:

    @Override
    public void onResume() {
      super.onResume();
      listview.setAdapter(adapter);
      adapter.notifyDataSetChanged();
    } 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top