Exemplo n.º 1
0
        private void ClickTranslate()
        {
            translateButton.Enabled = false;
            textByTranslate.Text    = translateLogic.ToTranslate(textForTranslate.Text);

            List <Android.Support.V4.App.Fragment> list = new List <Android.Support.V4.App.Fragment>()
            {
                this
            };
            int count = translateLogic.GetCountWords();

            if (count > 1)
            {
                list.Add(new WordsListFragment());
                pagerAdapter = new Adapters.TranslatePagesAdapter(Activity.SupportFragmentManager, list, 2);
                ViewPager pager = Activity.FindViewById <ViewPager>(Resource.Id.vp_fragments);
                pager.Adapter = pagerAdapter;
                pager.SetCurrentItem(0, true);

                saveText.SetCountWords(count);

                Toast toast = Toast.MakeText(Application.Context, "Листай вправо!", ToastLength.Long);
                toast.Show();
            }
            else
            {
                pagerAdapter = new Adapters.TranslatePagesAdapter(Activity.SupportFragmentManager, list, 1);
                ViewPager pager = Activity.FindViewById <ViewPager>(Resource.Id.vp_fragments);
                pager.Adapter = pagerAdapter;
                pager.SetCurrentItem(0, true);
                saveText.SetCountWords(count);
            }
        }
 public override void OnActivityCreated(Bundle savedInstanceState)
 {
     base.OnActivityCreated(savedInstanceState);
     indicator.SetViewPager(viewPager);
     if (TranslatorSave.NewInstance().GetCountWords == "one or null")
     {
         pagerAdapter = new Adapters.TranslatePagesAdapter(Activity.SupportFragmentManager, list, 1);
     }
     else
     {
         list.Add(new WordsListFragment());
         pagerAdapter = new Adapters.TranslatePagesAdapter(Activity.SupportFragmentManager, list, 2);
     }
     viewPager.Adapter = pagerAdapter;
     viewPager.SetCurrentItem(TranslatorSave.NewInstance().GetPosition, true);
 }
 public override void OnDestroy()
 {
     base.OnDestroy();
     try
     {
         Activity.SupportFragmentManager.BeginTransaction().Remove(pagerAdapter.GetItem(0)).Commit();
         pagerAdapter = TranslatorFragment.GetPagerAdapter;
         int countFragments = pagerAdapter?.Count ?? -1;
         if (countFragments == 2)
         {
             Activity.SupportFragmentManager.BeginTransaction().Remove(pagerAdapter.GetItem(1)).Commit();
         }
     }
     catch (Exception)
     {
         // ignored
     }
 }