public SecondTestPage(QuestionV2 question, int q)
        {
            InitializeComponent();
            qindex               = ++q;
            questionLabel.Text   = question.question;
            questionImage.Source = question.imageSource;
            correctAnswerString  = question.answer;

            char[] charArr = correctAnswerString.ToCharArray();

            Random random = new Random();

            for (int i = 0; i < charArr.Count(); i++)
            {
                int j    = random.Next(i + 1);
                var temp = charArr[j];
                charArr[j] = charArr[i];
                charArr[i] = temp;
            }
            foreach (char c in charArr)
            {
                CustomButton2 button = new CustomButton2
                {
                    Text            = c.ToString(),
                    HeightRequest   = 35,
                    WidthRequest    = 35,
                    Margin          = new Thickness(2.5),
                    BackgroundColor = Color.FromHex("#ffeed2")
                };
                buttonsFlexLayout.Children.Add(button);
                button.Clicked += Button_Clicked;
            }
        }
 void RemoveButtonInResult(CustomButton2 resultbutton, CustomButton2 answerbutton)
 {
     resultFlexLayout.Children.Remove(resultbutton);
     answerbutton.HeightRequest   = 35;
     answerbutton.WidthRequest    = 35;
     answerbutton.Margin          = new Thickness(2.5);
     answerbutton.BackgroundColor = Color.FromHex("#ffeed2");
     answerbutton.Text            = resultbutton.Text;
     answerbutton.IsEnabled       = true;
     ChangeResult(false);
 }
Ejemplo n.º 3
0
        private void Initialize()
        {
            try
            {
                MainLayout = MainContext.FindViewById <LinearLayout>(Resource.Id.llMain);

                CustomButton0 = MainContext.FindViewById <FrameLayout>(Resource.Id.llcustom0);
                CustomButton2 = MainContext.FindViewById <FrameLayout>(Resource.Id.llcustom2);
                CustomButton3 = MainContext.FindViewById <FrameLayout>(Resource.Id.llcustom3);
                CustomButton4 = MainContext.FindViewById <FrameLayout>(Resource.Id.llcustom4);
                CustomButton5 = MainContext.FindViewById <FrameLayout>(Resource.Id.llcustom5);

                CustomImage0 = MainContext.FindViewById <ImageView>(Resource.Id.ivcustom0);
                CustomImage2 = MainContext.FindViewById <ImageView>(Resource.Id.ivcustom2);
                CustomImage3 = MainContext.FindViewById <ImageView>(Resource.Id.ivcustom3);
                CustomImage4 = MainContext.FindViewById <ImageView>(Resource.Id.ivcustom4);
                CustomImage5 = MainContext.FindViewById <ImageView>(Resource.Id.ivcustom5);

                if (!UserDetails.IsLogin)
                {
                    CustomImage4.Visibility = ViewStates.Gone;
                    CustomImage5.Visibility = ViewStates.Gone;
                    MainLayout.WeightSum    = 3;
                }

                CustomButton0?.SetOnClickListener(this);
                CustomButton2?.SetOnClickListener(this);
                CustomButton3?.SetOnClickListener(this);
                CustomButton4?.SetOnClickListener(this);
                CustomButton5?.SetOnClickListener(this);

                CustomImage0.Background = null;
                CustomImage0.SetColorFilter(Color.ParseColor(AppSettings.MainColor));

                CustomImage2.Background = null;
                CustomImage2.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);

                CustomImage3.Background = null;
                CustomImage3.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);

                CustomImage4.Background = null;
                CustomImage4.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);

                CustomImage5.Background = null;
                CustomImage5.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
            }

            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        private void Button_Clicked(object sender, EventArgs e)
        {
            var button    = sender as CustomButton2;
            var newbutton = new CustomButton2
            {
                Text            = button.Text,
                HeightRequest   = 35,
                WidthRequest    = 35,
                Margin          = new Thickness(2.5),
                BackgroundColor = Color.Peru
            };

            newbutton.Clicked += (s2, e2) =>
            {
                RemoveButtonInResult(newbutton, button);
            };
            button.BackgroundColor = Color.Transparent;
            button.Text            = "";
            button.IsEnabled       = false;

            resultFlexLayout.Children.Add(newbutton);
            result += newbutton.Text;
            ChangeResult(true);
        }