Exemplo n.º 1
0
        private void PickedCurrenciesListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var item = elements.Single(x => x.CurrencyName == selectedCurrencies_Names[e.Position]);

            item.IsSelected = false;

            selectedCurrencies_Names.Remove(selectedCurrencies_Names[e.Position]);
            selectedCurrencies_Values.Remove(selectedCurrencies_Values[e.Position]);

            pickedCurrenciesListView = FindViewById <ListView>(Resource.Id.pickedCurrenciesListView);
            ArrayAdapter <string> pickedCurrAdapter = new ArrayAdapter <string>(this,
                                                                                Android.Resource.Layout.SimpleSelectableListItem,
                                                                                selectedCurrencies_Names);

            pickedCurrenciesListView.Adapter = pickedCurrAdapter;

            checkBoxListView = FindViewById <ListView>(Resource.Id.checkBoxListView);
            var chkListAfterUncheckingItem = PrepareData.XmlCurrencyNames(elements);
            var selectedIndex = chkListAfterUncheckingItem.FindIndex(a => a == item.CurrencyName);

            checkBoxListView.SetItemChecked(selectedIndex, false);

            if (selectedCurrencies_Names.Count == 0)
            {
                pickedCurrenciesListView.Visibility = ViewStates.Gone;
            }
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.SelectedCurrenciesLayout);

            checkBoxListView         = FindViewById <ListView>(Resource.Id.checkBoxListView);
            pickedCurrenciesListView = FindViewById <ListView>(Resource.Id.pickedCurrenciesListView);
            btn_okSelRates           = FindViewById <Button>(Resource.Id.btn_okSR);

            ISharedPreferences pref = Application.Context.GetSharedPreferences("ListPref", FileCreationMode.Private);
            var listJsonString      = pref.GetString("list", string.Empty);
            var elementsJson        = pref.GetString("elementsList", string.Empty);

            elements = (elementsJson == string.Empty)?PrepareData.elements:JsonConvert.DeserializeObject <List <SelectedItems> >(elementsJson); // przypisuje jeszcze raz dla adaptera przy zmianie orientacji

            selectedCurrencies_Names  = new List <string>();
            selectedCurrencies_Values = new List <string>();

            if (listJsonString != string.Empty)
            {
                var list = JsonConvert.DeserializeObject <List <ListForSharedPref> >(listJsonString);

                for (var i = 0; i < list.Count; i++)
                {
                    selectedCurrencies_Names.Add(list[i].Name);
                    selectedCurrencies_Values.Add(list[i].Value);
                }
            }
            else
            {
                selectedCurrencies_Names  = PrepareData.selectedCurrencies_Names;
                selectedCurrencies_Values = PrepareData.selectedCurrencies_Values;
            }

            if (elements.Count == 0)
            {
                try
                {
                    PrepareData.XmlCurrencyNamesToList(PrepareData.FormatXMLtoUTF8(url_tableA));
                    PrepareData.XmlCurrencyNamesToList(PrepareData.FormatXMLtoUTF8(url_tableB)); //tworze liste elementów 3 własciwosci
                }
                catch (Exception exc)
                {
                    AlertDialog.Builder mess = new AlertDialog.Builder(this);
                    mess.SetMessage(exc.Message);
                    mess.Show();
                }
            }


            namesList = PrepareData.XmlCurrencyNames(elements);
            ArrayAdapter <string> tablesAdapter = new ArrayAdapter <string>(this,
                                                                            Android.Resource.Layout.SimpleListItemMultipleChoice,
                                                                            namesList);
            ArrayAdapter <string> pickedCurrAdapter = new ArrayAdapter <string>(this,
                                                                                Android.Resource.Layout.SimpleSelectableListItem,
                                                                                selectedCurrencies_Names);

            pickedCurrenciesListView.Adapter = pickedCurrAdapter;
            checkBoxListView.Adapter         = tablesAdapter;
            checkBoxListView.ChoiceMode      = ChoiceMode.Multiple;

            if (selectedCurrencies_Names.Count != 0)
            {
                pickedCurrenciesListView.Visibility = ViewStates.Visible;
            }


            foreach (var i in elements) //checkuje przy recreate wczesniej zaznaczone
            {
                var el = selectedCurrencies_Names.Any(a => a == i.CurrencyName);
                if (el)
                {
                    var selectedIndex = namesList.IndexOf(i.CurrencyName);
                    elements[selectedIndex].IsSelected = true;
                    checkBoxListView.SetItemChecked(selectedIndex, true);
                }
            }

            date = PrepareData.GetDocumentDate(url_tableA); //data
            //pref.

            checkBoxListView.ItemClick         += CheckBoxListView_ItemClick;
            pickedCurrenciesListView.ItemClick += PickedCurrenciesListView_ItemClick;

            btn_okSelRates.Click += Btn_okSelRates_Click;
        }