コード例 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Check connectivity
            isConnected = Utils.CheckConnectivity(this);

            stopListView            = FindViewById <ListView>(Resource.Id.stopsListView);
            stopListView.ItemClick += StopListView_ItemClick;
            stopListView.SetMultiChoiceModeListener(new StopListMultChoiceHandler(this));

            // Get stops from DB
            db.CreateAllTables();

            // Set fragment that stores and updates stops
            departuresFragment = (DeparturesFragment)FragmentManager.FindFragmentByTag(TAG_TASK_FRAGMENT);

            if (Utils.CheckConnectivity(this))
            {
                // Activity first start, fragment not created
                if (departuresFragment == null)
                {
                    departuresFragment = new DeparturesFragment();
                    departuresFragment.TimeTableUpdated += Timetable_Updated;
                    FragmentManager.BeginTransaction().Add(departuresFragment, TAG_TASK_FRAGMENT).Commit();
                    requestTimetableUpdate();
                }
                // Fragment exists, but has no data - case when activity has been in background
                else if (departuresFragment != null && departuresFragment.Stops == null)
                {
                    departuresFragment.TimeTableUpdated += Timetable_Updated;
                    requestTimetableUpdate();
                }
                // Fragment exists with data - case when screen is rotated
                else
                {
                    adapter = new StopListAdapter(this, departuresFragment.Stops);
                    stopListView.Adapter = adapter;
                }
            }
            else
            {
                Toast.MakeText(this, Resources.GetString(Resource.String.no_connection), ToastLength.Long).Show();
            }
        }
コード例 #2
0
        // Process Departures Fragment event on timetable update
        private void Timetable_Updated(object sender, DepartureFragmentEventArgs e)
        {
            if (progressDialog != null)
            {
                progressDialog.Hide();
                progressDialog.Dismiss();
            }

            if (e.NoData)
            {
                Toast.MakeText(this, Resource.String.no_timetable_data, ToastLength.Short).Show();
                return;
            }

            // Update stops
            adapter = new StopListAdapter(this, departuresFragment.Stops);
            stopListView.Adapter = adapter;
        }