2016-09-06 15 views
3

객관식 질문을 생성하는 앱을 작업 중입니다. 사용자가 버튼 (라디오 버튼)을 선택하면 X (잘못된 경우) 또는 V (오른쪽 인 경우) 이미지가 선택한 답변 옆에 놓입니다. 모든 버튼이 포함 된 RadioGroup을 만들고 OnCheckedChanged Listener을 사용했습니다. 나는 그것이 작동하는지 확인하기 위해 인쇄 진술을 추적했다. 그러나 첫 번째 사용자 프레스를 제외하고 드로어 블 이미지를 전혀 표시하지 않습니다.버튼 오른쪽에 드로어 블 놓기

다른 말로하면, 사용자가 버튼 중 하나를 누르면 피드백 (V 또는 X)이 표시되지만 다른 버튼을 누르면 아무 것도 볼 수 없지만 로직이 작동 함에도 불구하고 (내에서 인쇄 문을 사용했습니다. 만약). 나는 SetCompoundDrawableWithIntrinsicBounds을 사용하고 그냥 작동합니다. 아무도이 문제를 해결하는 방법을 알고 있습니까?

저는 지난 8 시간 동안이 작업을하고있어 매우 실망했습니다.

리스너 코드 :

@Override 
     public void onCheckedChanged(RadioGroup group, int checkedId) { 
      //get the index of the correct answer 

      int indexAnswer = Integer.parseInt(myQuestion.getAnswer()) - 1; 
      for (int i = 0; i < possibleAnswers.length; i++) { 
       //if the button at position i was pressed 
       if (checkedId == possibleAnswers[i].getId()) { 
        //if its the correct answer 
        if (i == indexAnswer) { 
         Log.i("MyAcitvity", "thats correct"); 
         possibleAnswers[i].setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.checkmark, 0); 
        } 
        else { 
         Log.i("MyActivity", "thats wrong"); 
         possibleAnswers[i].setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.wrong, 0); 
        } 

       } else { 
        possibleAnswers[i].setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 
       } 
      } 
     } 
    }); 

덕분에 좋은 하루들 수 있습니다.

답변

0

나는 라디오 버튼을 먼저 얻고 다음과 같이 변경하는 것이 더 효과적이라고 생각한다.

View radioButton = group.findViewById(i); 
radioButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.checkmark, 0); 

더 나은 답변을 위해 특별히 당신을 radioGroup 관련이있는 그 모든 코드를 추가하십시오