Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

LegacyBarFragmentActivity

$
0
0

Hello! I'm already confused from trying to find the solution and test the solutions I found on Google, I decided to ask for help.

The source code posted below works perfectly, but need to get the value held in this variable strEmpresa = Intent.GetStringExtra ("strEmpresa").ToString (); CabecalhoTab class and assign the line view.FindViewById <TextView> (Resource.Id.fragment_text).Text = strEmpresa;
Does anyone know how to do this? Help!

using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Support.V4.App;
using Android.Support.V4.View;
using Android.Views;
using Android.Widget;
using Java.Lang;
using LegacyBar.Library.Adapters;
using LegacyBar.Library.BarActions;
using LegacyBar.Library.BarBase;

namespace street
{
    [Activity (Label = "XXXXXX", MainLauncher = false, LaunchMode = LaunchMode.SingleTop, Icon = "@drawable/logo", Theme = "@android:style/Theme.NoTitleBar", ScreenOrientation = ScreenOrientation.Portrait)]                      
    public class FragmentTabActivity : LegacyBarFragmentActivity
    {
        private TabHost _tabHost;
        private TabsAdapter _tabsAdapter;
        private ViewPager _viewPager;
        string strEmpresa = string.Empty;

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.fragment_tabs);

********strEmpresa = Intent.GetStringExtra ("strEmpresa").ToString ();*************

            _tabHost = FindViewById<TabHost> (Android.Resource.Id.TabHost);
            _tabHost.Setup ();

            _viewPager = FindViewById<ViewPager> (Resource.Id.pager);

            _tabsAdapter = new TabsAdapter (this, _tabHost, _viewPager);


            LegacyBar = FindViewById<LegacyBar.Library.Bar.LegacyBar> (Resource.Id.actionbar);
            LegacyBar.Title = "Ficha da Empresa";
            AddHomeAction (typeof(ActResultado), Resource.Drawable.logo);

            var spec = _tabHost.NewTabSpec ("tv");
            spec.SetIndicator ("Cadastro", Resources.GetDrawable (Resource.Drawable.logo));
            _tabsAdapter.AddTab (spec, Class.FromType (typeof(CabecalhoTab)), bundle);


            spec = _tabHost.NewTabSpec ("tab2");
            spec.SetIndicator ("Produtos", Resources.GetDrawable (Resource.Drawable.logo));
            _tabsAdapter.AddTab (spec, Class.FromType (typeof(ProdutosTab)), null);

            if (bundle != null) {
                _tabHost.SetCurrentTabByTag (bundle.GetString ("tab"));
            } else {
                _tabHost.CurrentTab = 0;
            }
        }

        protected override void OnSaveInstanceState (Bundle outState)
        {
            base.OnSaveInstanceState (outState);

            outState.PutString ("tab", _tabHost.CurrentTabTag);
        }
    }

    class CabecalhoTab : Android.Support.V4.App.Fragment
    {
        public override void OnCreate (Bundle p0)
        {
            base.OnCreate (p0);
            RetainInstance = true;
        }

        public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {

            var view = inflater.Inflate (Resource.Layout.simple_fragment, container, false);
            *********view.FindViewById<TextView> (Resource.Id.fragment_text).Text = strEmpresa;***********
            return view;
        }

        public override void OnActivityCreated (Bundle savedInstanceState)
        {
            base.OnActivityCreated (savedInstanceState);
        }
    }

    class ProdutosTab : Android.Support.V4.App.Fragment
    {
        public override void OnCreate (Bundle p0)
        {
            base.OnCreate (p0);
            RetainInstance = true;
        }

        public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate (Resource.Layout.simple_fragment, container, false);
            view.FindViewById<TextView> (Resource.Id.fragment_text).Text = "Fragment 2 ";
            return view;
        }

        public override void OnActivityCreated (Bundle savedInstanceState)
        {
            base.OnActivityCreated (savedInstanceState);
        }
    }
}

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>