Example #1
0
        private async void openRecordQuizAnswers()
        {
            //I have to put this text here to make sure the Answer List is ready when the RecordQuiz Answers page is opened.
            AnswerManager myAnswerManager = new AnswerManager();

            myAnswerManager.populateAnswers();

            await Navigation.PushAsync(new RecordQuizAnswers());
        }
Example #2
0
        private void PopulateUserList()
        {
            AnswerManager myAnswerManager = new AnswerManager();

            List <string> existingUsers = myAnswerManager.GetAllUserNames();

            TableSection section = new TableSection();

            foreach (String user in existingUsers)
            {
                Label lblUser = new Label();
                lblUser.Text     = user;
                lblUser.FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label));

                ViewCellHeader = new ViewCell()
                {
                    View = new StackLayout
                    {
                        Margin          = new Thickness(0, 10, 0, 0),
                        Orientation     = StackOrientation.Vertical,
                        VerticalOptions = LayoutOptions.Center,
                        Children        =
                        {
                            new StackLayout
                            {
                                Orientation = StackOrientation.Horizontal,
                                Children    =
                                {
                                    lblUser
                                }
                            }
                        }
                    }
                };

                ViewCellHeader.Tapped += (sender, e) =>
                {
                    //record which row item was clicked.
                    //I beleieve that there should be a method of passing data to a new page
                    //Like you can in iOS and Android but I was unable to find the Xamarin equivalent.

                    List <string> detailsClicked = user.Split('_').ToList <string>();

                    currentUsername          = detailsClicked[0];
                    ChooseQuiz.quizIdClicked = detailsClicked[1];

                    //Open the record quiz page
                    openRecordQuizAnswers();
                };

                //Add the viewcell to the section
                section.Add(ViewCellHeader);
            }

            //Add the section to the tableview
            tblExistingUsers.Root.Add(new TableSection[] { section });
        }
Example #3
0
        public RecordQuizAnswers()
        {
            InitializeComponent();

            //Set up the UI structure
            tblQuizes = new TableView
            {
                Intent = TableIntent.Data,
                Root   = new TableRoot("Questions"),
                MinimumHeightRequest = 100,
                // I have to put this line below so that Xamarin can render rows of different heights.
                //Taken from https://forums.xamarin.com/discussion/17471/can-you-have-dynamic-cell-heights-with-either-the-listview-or-tableview-views
                HasUnevenRows = true
            };

            Button btnSaveProgress = new Button
            {
                Text = "Save Progress",
                HorizontalOptions = LayoutOptions.Center,
                BackgroundColor   = Xamarin.Forms.Color.FromHex("fa00ff")
            };

            btnSaveProgress.Clicked += (sender, e) =>
            {
                AnswerManager myAnswerManager = new AnswerManager();
                myAnswerManager.WriteAnswersToDisk();
            };

            Button btnSubmit = new Button
            {
                Text = "Submit",
                HorizontalOptions = LayoutOptions.Center,
                BackgroundColor   = Xamarin.Forms.Color.FromHex("fa00ff")
            };

            section = new TableSection();

            this.Content = new StackLayout
            {
                Children =
                {
                    tblQuizes,
                    btnSaveProgress,
                    btnSubmit
                }
            };

            //Go and get the json data
            ReadQuiz();
        }
Example #4
0
        public void UpdateAnswerList(int qId, bool isMultiChc, bool isSelected, string ans)
        {
            bool wasfound = false;

            if (!isMultiChc)
            {
                foreach (AnswerManager a in Answers)
                {
                    //if the question already exists in the list
                    if (a.questionId == qId)
                    {
                        //It was found and updated
                        wasfound = true;
                        a.answer = ans;
                    }
                }
            }

            if (isMultiChc)
            {
                foreach (AnswerManager a in Answers)
                {
                    if (a.questionId == qId && a.answer == ans)
                    {
                        wasfound = true;
                        a.isMultipleChoiceSelected = isSelected;
                    }
                }
            }

            //if the question does not exist then create it and add to the list
            if (!wasfound)
            {
                AnswerManager anotherAnswer = new AnswerManager();
                anotherAnswer.questionId               = qId;
                anotherAnswer.isMultipleChoice         = isMultiChc;
                anotherAnswer.answer                   = ans;
                anotherAnswer.isMultipleChoiceSelected = isSelected;
                Answers.Add(anotherAnswer);
            }
        }