There is a RecyclerView, it has CardView, which contains a TextView. Everything is filled in the adapter. Everything is working.
In the activation, I get the font size from the dialog and I want, what after that the TextView in CardView would be displayed by this font size. But everything is displayed in the size that was specified during creation.
How to implement this change the font size during the execution of the application?
In PostAdapter:
private int mFontSize; ... public void setFontSize(int fontSize) { mFontSize = fontSize; } public ViewHolder onCreateViewHolder{ View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post, parent, false); TextView tvpost = (TextView) v.findViewById(R.id.postitem_post); tvpost.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSize); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, tvpost.getLineHeight() * LINE_COUNT_FOR_SHORT_VIEW); tvpost.setLayoutParams(lp); return new ViewHolder(v); } @Override public void onBindViewHolder(final ViewHolder holder, int position) { PostModel post = posts.get(position); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { holder.post.setText(Html.fromHtml(post.getElementPureHtml(), Html.FROM_HTML_MODE_LEGACY)); } else { holder.post.setText(Html.fromHtml(post.getElementPureHtml())); } holder.post.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSize); ... In MainActivity:
@Override protected void onCreate(Bundle savedInstanceState) { ... PostAdapter adapter = new PostAdapter(this, mPosts, mFontSize); mRvPosts.setAdapter(adapter); ... } //Сюда возвращаемся после выхода из настроек @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // читаем размер шрифта из ListPreference mFontSize = Integer.parseInt(prefs.getString(getString(R.string.pref_font_size), "18")); PostAdapter pa = (PostAdapter) mRvPosts.getAdapter(); pa.setFontSize(mFontSize); mRvPosts.getAdapter().notifyDataSetChanged(); super.onActivityResult(requestCode, resultCode, data); } When the application is restarted, it works, the font size changes, and when it is changed in the settings and in the running application ...