Exemplo n.º 1
0
        private void ButtonAdd_Click(object sender, EventArgs e)
        {
            if (towns.Find(t => t.Name == editName.Text) != null)
            {
                editName.Text = null;
                return;
            }
            TownWeather town = new TownWeather(editName.Text);

            dbAdapter.Insert(town);
            new WeatherTask(this).Execute(town.Name);
            editName.Text = null;
            LoadData();
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;

            listData = FindViewById <ListView>(Resource.Id.listViewTowns);

            dbAdapter = new DataBaseAdapter();
            dbAdapter.CreateTable();

            editName        = FindViewById <EditText>(Resource.Id.textInputEditText);
            editName.Click += delegate
            {
                Button buttonEdit = FindViewById <Button>(Resource.Id.buttonEdit);
                if (buttonEdit.Text == "")
                {
                    editName.Text = null;
                }
            };

            BindButtons();

            LoadData();

            listData.ItemClick += ListData_ItemClick;

            if (towns.Count == 0)
            {
                TownWeather moskow = new TownWeather("Moscow");
                towns.Add(moskow);
                dbAdapter.Insert(moskow);
                new WeatherTask(this).Execute(moskow.Name);
                TownWeather peterburg = new TownWeather("Saint Petersburg");
                towns.Add(peterburg);
                dbAdapter.Insert(peterburg);
                new WeatherTask(this).Execute(peterburg.Name);
            }
        }