Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Why T

$
0
0

Hi,

I have below code which is a ListView contains ItemTemplate has Switch control.

The problem here that every time I open the page it shows the Alert in SwitchSettingsPushNotifications_Toggled

I don't want to show the alert OnAppearing so I had to use is_shown but although I set the is_shown to true it is still showing the Alert OnAppearing

How can I avoid this please?

using System;
using System.Collections.Generic;
using Plugin.Geolocator;
using Xamarin.Forms;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Com.OneSignal;
using System.ComponentModel;
using Syncfusion.ListView.XForms;
// using ModernHttpClient;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using System.Net;
using System.Threading;
using System.Globalization;
using Xamarin.Auth;

namespace Eithar
{
    public partial class Settings : ContentPage
    {
        private bool is_shown = false;

        public Settings()
        {
            InitializeComponent();
        }

        protected async override void OnAppearing()
        {
            base.OnAppearing();

            LabelSettingsMemberID.Text = App.getUserInfo("EitharMemberID");

            GetNotificationSetting();

            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            var position = await locator.GetPositionAsync();

            LabelLatitude.Text = position.Latitude.ToString();
            LabelLongitude.Text = position.Longitude.ToString();
        }

        public async void GetNotificationSetting()
        {
            try
            {
                ListViewSettingsnotifications.IsVisible = false;

                loadingSettingsNotifications.IsBusy = true;
                loadingSettingsNotifications.IsVisible = true;

                var client = new HttpClient();
                client.BaseAddress = new Uri("https://www.domain.com/ws/populate_settings_notifications.php?member=" + App.getUserInfo("EitharMemberGuid"));

                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await client.GetAsync("https://www.doman.com/ws/populate_settings_notifications.php?member=" + App.getUserInfo("EitharMemberGuid"));

                if (response.IsSuccessStatusCode)
                {
                    var data = await response.Content.ReadAsStringAsync();

                    var result = JsonConvert.DeserializeObject<List<NotificationsModel>>(data);
                    ObservableCollection<NotificationsModel> trends = new ObservableCollection<NotificationsModel>(result);

                    ListViewSettingsnotifications.ItemsSource = trends;

                    loadingSettingsNotifications.IsVisible = false;
                    loadingSettingsNotifications.IsBusy = false;

                    ListViewSettingsnotifications.IsVisible = true;

                    is_shown = true;
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Home", ex.Message, "Ok");
                return;
            }
        }

        private void SwitchSettingsPushNotifications_Toggled(object sender, ToggledEventArgs e)
        {
            if (is_shown == false) return;

            DisplayAlert("Alert","Tapped item ID: " + ((sender as Switch).BindingContext as NotificationsModel).settings_notifications_id,"OK");
        }
    }
}

Thanks,
Jassim


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>