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?

Posts

  • 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);
    mPager.Adapter=mAdapter;
    
        mIndicator = FindViewById<CirclePageIndicator> (Resource.Id.indicador);
    mIndicator.SetViewPager (mPager, ItemSelected);
    mIndicator.SetCurrentItem(ItemSelected);
    
    mIndicator.SetSnap(true);
    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:
        //Pequeño
        intFontSize = Android.Resource.Style.TextAppearanceSmall;
        TextoNoticia.SetTextAppearance(this,Android.Resource.Style.TextAppearanceSmall);
        break;
    
                case 1:
        //Mediano
        intFontSize = Android.Resource.Style.TextAppearanceMedium;
        TextoNoticia.SetTextAppearance(this,Android.Resource.Style.TextAppearanceMedium);
        break;
    
               case 2:
        //Grande
        intFontSize = Android.Resource.Style.TextAppearanceLarge;
        TextoNoticia.SetTextAppearance(this,Android.Resource.Style.TextAppearanceLarge);
        break;
    }
    
    PutPreferenceToPhone("TextAppearence_Noticia_Text", Convert.ToString(intFontSize));
    
    
    mPager.RefreshDrawableState();
    mAdapter.NotifyDataSetChanged();
    
    
        // ***** Here put the Invalidate like *********
    
        mPager.Invalidate();
    
        // ****** 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.