Example #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            tripItem = JsonConvert.DeserializeObject <TripItem>(Intent.GetStringExtra("Trip"));
            friends  = new ObservableCollection <UserItem>();
            friends  = JsonConvert.DeserializeObject <ObservableCollection <UserItem> >(Intent.GetStringExtra("Friends"));
            try
            {
                paymentItem = JsonConvert.DeserializeObject <PaymentItem>(Intent.GetStringExtra("Payment"));
            }
            catch (Exception) {
                paymentItem = null;
            }

            friendsList.Add(new UserItem {
                Name = "Choose friend"
            });
            friendsList.AddRange(friends);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.PaymentAddLayout);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbarAddPay);
            SetSupportActionBar(toolbar);
            SupportActionBar.SetDefaultDisplayHomeAsUpEnabled(true);



            Spinner spinner = FindViewById <Spinner>(Resource.Id.spinnerFriendsToPayment);

            listView     = FindViewById <ListView>(Resource.Id.listViewFriendsToPayment);
            editText     = FindViewById <TextView>(Resource.Id.textView6);
            viewSwitcher = FindViewById <ViewSwitcher>(Resource.Id.viewSwitcher1);
            //viewSwitcher.ShowNext();
            payName       = viewSwitcher.FindViewById <EditText>(Resource.Id.editTextName);
            payNameStatic = viewSwitcher.FindViewById <TextView>(Resource.Id.editTextNameNot);
            payNameStatic.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(20) });
            payName.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(20) });

            //editText.TextChanged += EditText_TextChanged;
            var swipeContainer = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeContainer);

            swipeContainer.SetColorSchemeResources(Android.Resource.Color.HoloBlueLight, Android.Resource.Color.HoloGreenLight, Android.Resource.Color.HoloOrangeLight, Android.Resource.Color.HoloRedLight);
            swipeContainer.Refresh += SwipeContainer_Refresh;
            var button  = FindViewById <Button>(Resource.Id.button1);
            var button2 = FindViewById <Button>(Resource.Id.button2);

            button.Click += delegate {
                buttonClicked();
            };

            button2.Click        += Button2_Click;
            spinner.ItemSelected += spinner_ItemSelected;

            var adapter = new ArrayAdapter <UserItem>(this, Android.Resource.Layout.SimpleSpinnerItem, friendsList);

            spinner.Adapter  = adapter;
            friendsToPayment = new List <Tuple <string, decimal> >();
            if (paymentItem != null)
            {
                var friends_List = new List <UserItem>(friends);
                editText.Text      = "" + paymentItem.Amount;
                payNameStatic.Text = paymentItem.Name;
                button.Text        = "Edit";
                button2.Visibility = ViewStates.Visible;
                viewSwitcher.ShowNext();

                // foreach (var pay in payments)
                // {
                //   var item = friends_List.Find(i => i.Id == pay.UserId);
                //    Tuple <string, decimal> tup = new Tuple<string, decimal>(item.Name, pay.Amount);
                //    friendsToPayment.Add(tup);
                //}
            }
            getPayments();
            //var adapterPayemnt = new PaymentAddAdapter(this, friendsToPayment);

            //listView.Adapter = adapterPayemnt;
        }