2016-04-06 14 views
0

ユーザーがAppbarボタンをクリックしてリストに保存した後、ラジオボタンのタグとグループ名をすべて選択する必要があります。異なるグループからリストへのラジオボタン選択の保存

だから私は、サーバーからのリストを持つユーザーが投稿した回答リスト..私は

質問2で別のラジオボタンをクリックしたときに、私は、リストの上に書かれている=「Answer_Checked」チェックを使用する場合

を比較することができます

コーディング

var result1 = await response1.Content.ReadAsStringAsync(); 
      var objResponse1 = JsonConvert.DeserializeObject<List<RootObject>>(result1); 

      var result2 = await response2.Content.ReadAsStringAsync(); 
      var objResponse2 = JsonConvert.DeserializeObject<List<AnswerObject>>(result2); 

      for (int i = 0; i < objResponse1.LongCount(); i++) 
      { 
       ObservableCollection<Option> options1 = new ObservableCollection<Option>(); 
       for (int j = 0; j < objResponse2.LongCount(); j++) 
       { 
        if (objResponse1[i].id == objResponse2[j].question_id) 
        { 
         options1.Add(new Option() { QuestionAnswer = objResponse2[j].answer, IsCorrect = objResponse2[j].is_right_option, groupname = objResponse2[j].question_id.ToString() }); 
        } 
       } 
       questions.Add(new Question() { QuestionName = objResponse1[i].question, qno=i + 1, qcount =objResponse1.Count, options = options1 }); 
      } 
      flipView.ItemsSource = questions; 

XAMLコーディング

public class RootObject 
    { 
     public RootObject(int id, string question, int qno, int qcount) 
     { 
      this.id = id; 
      this.question = question; 
      this.qcount = qcount; 
      this.qno = qno; 
     } 
     public int id { get; set; } 
     public string question { get; set; } 
     public int qcount { get; set; } 
     public int qno { get; set; } 
     public int time { get; set; } 
    } 

public class AnswerObject 
    { 
     public AnswerObject(int question_id, int answer_id, string answer, int is_right_option) 
     { 
      this.question_id = question_id; 
      this.answer_id = answer_id; 
      this.answer = answer; 
      this.is_right_option = is_right_option; 
     } 
     public int question_id { get; set; } 
     public int answer_id { get; set; } 
     public string answer { get; set; } 
     public int is_right_option { get; set; } 
    } 

    public class Question 
    { 
     public string QuestionName { get; set; } 
     public int qcount { get; set; } 
     public int qno { get; set; } 

     public ObservableCollection<Option> options { get; set; } 
    } 

    public class Option 
    { 
     public string QuestionAnswer { get; set; } 
     public string groupname { get; set; } 
     public int IsCorrect { get; set; } 
    } 

のC# JSON形式でJSON形式で10

回答

[{"question_id":3,"answer_id":1,"answer":"10%","is_right_option":0},{"question_id":3,"answer_id":2,"answer":"10.25%","is_right_option":1},{"question_id":3,"answer_id":3,"answer":"10.5%","is_right_option":0},{"question_id":3,"answer_id":4,"answer":"None of these","is_right_option":0},{"question_id":4,"answer_id":5,"answer":"Rs. 2.04","is_right_option":1},{"question_id":4,"answer_id":6,"answer":"Rs. 3.06","is_right_option":0},{"question_id":4,"answer_id":7,"answer":"Rs. 4.80","is_right_option":0},{"question_id":4,"answer_id":8,"answer":"Rs. 8.30","is_right_option":0}] 

質問

[{"id":3,"question":"An automobile financier claims to be lending money at simple interest, but he includes the interest every six months for calculating the principal. If he is charging an interest of 10%, the effective rate of interest becomes: ","time":1},{"id":4,"question":"What is the difference between the compound interests on Rs. 5000 for 1 years at 4% per annum compounded yearly and half-yearly? ","time":1}] 
+0

を使用して、それを解決しました。また、実行可能なプロジェクトは、作成するよりもあなたに答えを与えるのに役立ちます。 – Jerin

+0

リストの代わりに辞書を作成して解決したと思います。私はhttp://pastebin.com/dbWbfQuPでした。 – Digi23

+0

それがうまくいけば解決します。あなたの答えを貼り付けて、他の人が参照できるように答えてください。よく辞書はリストのように働いていますが、追加する前に項目がすでにリストに存在するかどうかをチェックしていない可能性があります。あなたが選択した特定の回答が維持されているか否かを前後にナビゲートしているときに、あなたの回答の状態をチェックしてください。 – Jerin

答えて

0

私は、あなたが主な機能 `Answer_Checked`を提供haventは辞書を使用して代わりのリスト

private void Answer_Checked(object sender, RoutedEventArgs e) // Radio button click 
    { 
     var radio = sender as RadioButton; 
     bool check = Convert.ToBoolean(radio.IsChecked); 
     if(check) 
     { 
      Answer[Convert.ToInt16(radio.GroupName)] = Convert.ToInt16(radio.Tag); 
     } 
    } 

    public async void Check_Result() // Evaluate result 
    { 
     foreach (KeyValuePair<int, int> count in Answer) 
     { 
      if (count.Value == 1) 
      { 
       result++; 
      } 
     } 
     MessageDialog showresult = new MessageDialog(result.ToString()); 
     await showresult.ShowAsync(); 
     Frame.Navigate(typeof(MainPage), null); 
    } 


    public void TestSubmit_Click(object sender, RoutedEventArgs e) // AppBar button click 
    { 
     Check_Result(); 

    } 
関連する問題