2015-01-04 4 views
2

내 논문 작업 LogCat에서 내 코드에 영향을 줄 수 있다고 경고하는 경고가 표시됩니다.내 체크 박스가 instanceof처럼 보이지 않는다 CheckBox

일부 데이터가 포함 된 JSON이 표시되며 확인란과 라디오 버튼 (라디오 그룹)이있는 레이아웃을 프로그래밍 방식으로 프로그래밍해야합니다. 내가 getChildAt 때 나중에 내가 여기이 설문 조사를 투표 할 수 있습니다 것이 내 문제의 원인() 내 레이아웃

if(child instanceof CheckBox) 

이 작동하지 않습니다와 나는 이유를 이해할 수있다. 코드는 경고가 무슨 말을입니다 else if 블록을 입력하지 않도록

ll = (LinearLayout) findViewById(R.id.llSurvey); //OnCreate 

    /*Creating CheckBox*/ 
      String votes = jObj.getString("votes"); 
      String label = jObj.getString("label"); 
      String usid = jObj.getString("USID");  
      if(uType.equals("multi")){ 
       CheckBox cb = new CheckBox(SingleSurvey.this); 
       cb.setText(label + " (" + votes + ")"); 
       cb.setId(s+1000); 
       ll.addView(cb);   
       Log.i("MULTI_TYPE", "usid: " + usid + " id: " + cb.getId()); 
      } 
      s++; 

    /*Voting*/ 

      for(int i = 0; i < ll.getChildCount(); i++){ 
       View child = ll.getChildAt(i); 
       int p = child.getId(); 
       Log.i("CHILD ID", "id: " + p); 

       if(child instanceof TextView){ 
        continue; 
       } 

       else if(child instanceof CheckBox){ 
        Log.i("INSTANCE OF CB", "checkbox"); 
        CheckBox cb = (CheckBox) child; 
        if(cb.isChecked()){ 
         int cbId = cb.getId(); 
         usid = rb_usid[cbId]; 
         Log.i("CHECKBOX", "usid: " + usid); 
        } 
       } 

       //some other stuff 
      } 
+2

확인. 나는 나를 때 리려고 갈거야. – user58923

답변

4

Checkbox 클래스가하는 TextView 서브 클래스 :

여기 내 코드입니다.

android.widget.TextView 
     ↳android.widget.Button 
      ↳android.widget.CompoundButton 
       ↳android.widget.CheckBox