2016-04-29 18 views
-2

我獲取JSON數據對於我的測驗應用程序,如何匹配答案並增加計數,如果它是正確的?

JSON數據如下:

 { 
    "results":[ 
    { 
    "id":4, 
    "ps":"Besides gases, air also contains", 
    "op1":"Smoke", 
    "op2":"Water vapour", 
    "op3":"Dust particles", 
    "op4":"All of these", 
    "resType":"multiple", 
    "ans1":null, 
    "ans2":null, 
    "ans3":null, 
    "ans4":"Yes",}...... 
     ....... 

我存儲所有接收到的數據中的ArrayList如下:

 questionList = new ArrayList<String>(); 
     opList1 = new ArrayList<>(); 
     opList2 = new ArrayList<>(); 
     opList3 = new ArrayList<>(); 
     opList4 = new ArrayList<>(); 

     answer1 = new ArrayList<>(); 
     ......................... 
     ......................... 

上的每個按鈕點擊我有做了這樣的事情:

 Button op1, op2, op3, op4;  
     int count;(GLobal) 

     public void onClick(View v) {     

     String message = op4.getText().toString(); 
     TextView show = (TextView) findViewById(R.id.textViewChoice); 

     Toast.makeText(getBaseContext(), message, 1000).show(); 
       show.setText(message); 

     if (op4.getText().equals("Yes")) { 
      count = count + 1; 
     } else if (op4.getText().equals("null")) 
      count = count; 
     } 

每當我的計數= 0

+0

檢查op4.getText()值? – sasikumar

+0

在這裏你的邏輯是完全錯誤的!你必須得到「ans4」對象,然後與條件匹配! –

+0

opList4.add(mcq.get(currentPosition).getOp4()); op.setText(mcq.get(currentPosition).getOp4()。toString()); –

回答

0

你的邏輯應該喜歡這個

public void onClick(View v) { 
    case R.id.op1 :{ 
    if(ans4.equals("yes")) { 
     counter++; 
    } 
    } 
    case R.id.op2 :{ 
    if(ans2.equals("yes")) { 
    counter++; 
    } 
    } 
} 
相關問題