2012-02-23 5 views
28

버튼을 클릭 할 때 확인란의 값을 선택해야합니다. 자바 코드 :Android : 체크 박스 값 확인

dualcamera1 = (CheckBox)findViewById(R.id.Camera1_DualDisplay); 
dualcamera2 = (CheckBox)findViewById(R.id.Camera2_DualDisplay); 
dualcamera3 = (CheckBox)findViewById(R.id.Camera3_DualDisplay); 
dualcamera4 = (CheckBox)findViewById(R.id.Camera4_DualDisplay); 
dualdisplay = (Button)dialog.findViewById(R.id.DisplayDualVideo); 
+0

확인란의 값을 가져 오시겠습니까? 확인란의 상태 또는 다른 것을 알고 싶습니까? 귀하의 요구 사항을 조금 더 설명하십시오. – Hiral

+0

사용자가 단일을 선택하면 두 개 이상의 확인란을 선택해야합니다. 여러 개 이상의 확인란을 사용하여 메시지를 표시해야합니다. 버튼을 클릭하면 체크 된 체크 박스 값을 알아야합니다. – Kamal

+0

아직 명확하지 않습니다. 사용자가 2 개 이하의 확인란을 선택하지 못하도록하고 싶습니까? 체크 박스의 값이나 체크 된 상태 또는 텍스트의 의미는 무엇입니까? – Hiral

답변

6

올바른 옵션은 Checkbox 값을 얻기 위해

의 IsChecked() 현재 검사 합계 : 상기 방법을 사용 이보기는 그렇지 않은 경우는 false, 사용할 수있는 경우보기

dualcamera1.isChecked() 

isEnable()의 전자는 True를 반환.

26

당신은 그것의 상태를 확인하기 위해 체크 박스에 isChecked()를 호출 할 수 있습니다. 체크 박스 수를 셀 수 있으면 ArrayList에 저장하고 루프 할 수 있습니다.

+0

맞아요. ❤ – mghhgm

39

그것의 간단한 : 그 선택된 경우에만 루프에서, 선택되어있는 경우에

static int m=0; 
dualDisplay.setOnClickListener(new OnCli....{ 
    onClick() 
    { 
      if(dualcamera1.isChecked()) 
       m++; // you can save this as checked somewhere 
      if(dualcamera2.isChecked()) 
       m++; // you can save this as checked somewhere 
      if(dualcamera3.isChecked()) 
       m++; // you can save this as checked somewhere 
      if(dualcamera4.isChecked()) 
       m++; // you can save this as checked somewhere 
    } 
}); 
if(m>2 || m<2) 
     // show error message 
else 
     // code here 

는 당신이 체크 박스의 세부 사항을 저장할 수 있습니다.

7

이 당신을 도울 수 있습니다

//Returns the enabled status for this view. 
dualcamera1.isEnabled() //return True if this view is enabled, false otherwise. 

//Indicates whether the view is currently in pressed state. 
dualcamera1.isPressed() //return True if this view is enabled, false otherwise. 
17

를 체크 박스 (에서 onCreate에 정의되어 있지 않은 경우) 방법은 다음과 같이 뭔가를 사용해야합니다 :

boolean isChecked = ((CheckBox) findViewById(R.id.checkBox1)).isChecked()