protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Context mContext = Android.App.Application.Context; AppPreferences ap = new AppPreferences(mContext); string userId = ap.GetUserId(); if (Convert.ToInt32(userId) == 0) { var newIntent = new Intent(this, typeof(LoginActivity)); StartActivity(newIntent); } adapter = new TabsAdapter(this, SupportFragmentManager); pager = FindViewById <ViewPager>(Resource.Id.viewpager); var tabs = FindViewById <TabLayout>(Resource.Id.tabs); pager.Adapter = adapter; tabs.SetupWithViewPager(pager); pager.OffscreenPageLimit = 3; pager.PageSelected += (sender, args) => { var fragment = adapter.InstantiateItem(pager, args.Position) as IFragmentVisible; fragment?.BecameVisible(); }; Toolbar.MenuItemClick += (sender, e) => { var intent = new Intent(this, typeof(LoginActivity)); string _userId = "0"; ap.SaveUserId(_userId); StartActivity(intent); }; SupportActionBar.SetDisplayHomeAsUpEnabled(false); SupportActionBar.SetHomeButtonEnabled(false); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Context mContext = Android.App.Application.Context; AppPreferences ap = new AppPreferences(mContext); string userId = ap.GetUserId(); if (Convert.ToInt32(userId) == 0) { var newIntent = new Intent(this, typeof(LoginActivity)); StartActivity(newIntent); } adapter = new TabsAdapter(this, SupportFragmentManager); pager = FindViewById <ViewPager>(Resource.Id.viewpager); searchBar = FindViewById <TextInputLayout>(Resource.Id.search_textInputLayout); searchEditText = FindViewById <TextInputEditText>(Resource.Id.searchedTxt); var tabs = FindViewById <TabLayout>(Resource.Id.tabs); pager.Adapter = adapter; tabs.SetupWithViewPager(pager); pager.OffscreenPageLimit = 3; searchBar.Visibility = ViewStates.Gone; pager.PageSelected += (sender, args) => { var fragment = adapter.InstantiateItem(pager, args.Position) as IFragmentVisible; fragment?.BecameVisible(); }; searchEditText.Click += (sender, eventArgs) => { searchBar.Visibility = ViewStates.Gone; Toolbar.Visibility = ViewStates.Visible; InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService); imm.HideSoftInputFromWindow(searchEditText.WindowToken, 0); }; searchEditText.TextChanged += (sender, eventArgs) => { if (searchEditText.Text.Trim().Length > 1) { FacilityFragment fragment = (FacilityFragment)SupportFragmentManager.Fragments[0]; if (fragment != null) { fragment.SearchFacilities(searchEditText.Text.Trim()); } } }; Toolbar.MenuItemClick += (sender, e) => { var itemTitle = e.Item.TitleFormatted; switch (itemTitle.ToString()) { case "Log Out": var intent = new Intent(this, typeof(LoginActivity)); string _userId = "0"; ap.SaveUserId(_userId); StartActivity(intent); break; case "Search": searchBar.Visibility = ViewStates.Visible; Toolbar.Visibility = ViewStates.Gone; break; } }; SupportActionBar.SetDisplayHomeAsUpEnabled(false); SupportActionBar.SetHomeButtonEnabled(false); }