示例#1
0
        public async void populateChoices(View view)
        {
            //query to server
            int id = -1;

            options = new List <Option> (await LessonUtil.GetOptionsByScreenAsync(lesson_id, screen.Id + ""));
            var activity = Activity as ScreensActivity;

            if (activity.answer.ContainsKey(screen.Id))
            {
                id = int.Parse(activity.answer [screen.Id]);
            }
            for (int i = 0; i < options.Count; i++)
            {
                Option option = options [i];
                if (option != null)
                {
                    RadioButton rdBtn = new RadioButton(Application.Context);
                    rdBtn.Id = (i);
                    if (!option.Title.Contains("."))
                    {
                        rdBtn.Text = Utils.populateSelection(option.Order) + ". " + option.Title;
                    }
                    rdBtn.SetTextSize(ComplexUnitType.Sp, 18.0f);
                    if (i == id)
                    {
                        //set checked
                        rdBtn.Checked = true;
                    }
                    choicesRadioGroup.AddView(rdBtn);
                }
            }
            //remove default selected
            if (id == -1)
            {
                (choicesRadioGroup as RadioGroup).ClearCheck();
            }
            activity.validateBtns();
        }
示例#2
0
        private async void getCorrectAnswerFromServer()
        {
            //get correct answer
            foreach (var screen in Constants.screens)
            {
                string type = screen.Type;
                if (type != null)
                {
                    if (type.Equals("question") || type.Equals("audio_question") || type.Equals("question_audio"))
                    {
                        IList <Option> list = await LessonUtil.GetOptionsByScreenAsync(Intent.GetIntExtra(Constants.LESSON_ID, 0), screen.Id + "");

                        options = new List <Option> (list);
                        foreach (var option in options)
                        {
                            if (option.Detail == true)
                            {
                                correctAnswers.Add(screen.Id, option.Id);
                                switch (option.Order)
                                {
                                case 0:
                                    standardAnswer.Add("A");
                                    break;

                                case 1:
                                    standardAnswer.Add("B");
                                    break;

                                case 2:
                                    standardAnswer.Add("C");
                                    break;

                                case 3:
                                    standardAnswer.Add("D");
                                    break;

                                case 4:
                                    standardAnswer.Add("E");
                                    break;

                                case 5:
                                    standardAnswer.Add("F");
                                    break;

                                case 6:
                                    standardAnswer.Add("G");
                                    break;

                                default:
                                    standardAnswer.Add("H");
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            //send answer to server
            await SendLessonAnswers(Intent.GetIntExtra(Constants.LESSON_ID, 0), Constants.screenAnswers);

            //judge how many right
            foreach (var answer in Constants.screenAnswers)
            {
                if (correctAnswers.ContainsKey(answer.ScreenId))
                {
                    if (correctAnswers [answer.ScreenId] == answer.OptionId)
                    {
                        //correct
                        correct++;
                        right.Add(true);
                    }
                    else
                    {
                        right.Add(false);
                    }
                }
            }
            //complement
            for (int i = right.Count; i < standardAnswer.Count; i++)
            {
                right.Add(false);
            }
            //set adapter
            adapter          = new ResultListViewAdapter(this);
            lv_score.Adapter = adapter;
            pb_anti.Max      = standardAnswer.Count;
            pb_anti.Progress = correct;
            int score = (int)((correct / (float)standardAnswer.Count) * 100);

            if (score <= 50)
            {
                tv_initiate.SetTextColor(Color.Red);
            }
            else
            {
                tv_initiate.SetTextColor(Color.Green);
            }
            tv_initiate.Text = "Score:" + score;
        }