Need help with ViewPager updating TextView font-size instantly

alexmenalexmen ESMember
edited April 2013 in Xamarin.Android

I have a TextView in all page inside ViewPager. When I try to change the textview font size in all page, it doesn't updated the current page because problably ViewPager caches the recent views. So when I navigate to further pages, I can see the changes. How can I make the current page show the changes.

Anybody help me?


  • CheesebaronCheesebaron DKInsider, University mod

    Have you tried calling Invalidate() on the view you are changing font size on?

  • alexmenalexmen ESMember

    I tried but does nothing

  • CheesebaronCheesebaron DKInsider, University mod

    Can you maybe show us how you are doing it? And are you calling Invalidate on the correct thread?

  • alexmenalexmen ESMember
    edited April 2013

    in OnCreate, I do this:

    protected override void OnCreate (Bundle bundle)
    mAdapter = new NoticiaItemAdapter(SupportFragmentManager,mListItems);
    mPager = FindViewById<ViewPager> (Resource.Id.paginador);
        mIndicator = FindViewById<CirclePageIndicator> (Resource.Id.indicador);
    mIndicator.SetViewPager (mPager, ItemSelected);
    mIndicator.SetOnPageChangeListener (this);

    In OnCreateOptionsMenu, I put a SubMenu with one item to modify the font size, when you select this subMenu open an alertDialog.Builder with 3 different font size.

    If you select an option that run this function

    private void ListClicked (object sender, DialogClickEventArgs e)
       int intFontSize =0;
       TextView TextoNoticia = (TextView)FindViewById(Resource.Id.DescripcionNoticia);
    switch (e.Which) {
        case 0:
        intFontSize = Android.Resource.Style.TextAppearanceSmall;
                case 1:
        intFontSize = Android.Resource.Style.TextAppearanceMedium;
               case 2:
        intFontSize = Android.Resource.Style.TextAppearanceLarge;
    PutPreferenceToPhone("TextAppearence_Noticia_Text", Convert.ToString(intFontSize));
        // ***** Here put the Invalidate like *********
        // ****** and like this *******
    RunOnUiThread(() => { mPager.Invalidate();});   
  • CheesebaronCheesebaron DKInsider, University mod

    You need to do it on the actual view you are setting the text size of and not the ViewPager.

Sign In or Register to comment.