2012-12-04 3 views
0

내 안드로이드 앱에 문제가 있습니다 두 번째 버튼을 클릭하면 처음 작동합니다.하지만 두 번째 버튼을 클릭하면 그의 작업과 주먹 작업이 수행됩니다. 이것은 코드입니다. 다음 XML 방법두 개의 라디오 버튼이 제대로 작동하지 않습니다.

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
    // TODO Auto-generated method stub 
    switch(buttonView.getId()){ 
    case R.id.rbYes: 
     flag=true; 
     etLastHourse.setEnabled(flag); 
     etLastHourse.setBackgroundColor(Color.WHITE); 
     etLastGPA.setEnabled(flag); 
     etLastGPA.setBackgroundColor(Color.WHITE); 
     Toast.makeText(getApplicationContext(), "OK1", Toast.LENGTH_LONG).show(); 

    break; 
    case R.id.rbNo: 
     Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_LONG).show(); 
     flag=false; 
     etLastHourse.setEnabled(flag); 
     etLastHourse.setEnabled(flag); 
     etLastHourse.setBackgroundColor(Color.GRAY); 
     etLastGPA.setEnabled(flag); 
     etLastGPA.setBackgroundColor(Color.GRAY); 



    break; 

    } 
} 

의 ID

rbYes = (RadioButton) findViewById(R.id.rbYes); 
    rbNo = (RadioButton) findViewById(R.id.rbNo); 

위한

에게

당신이 첫 번째 버튼을 누르면
<RadioButton 
      android:id="@+id/rbNo" 
      style="@style/RadioButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#FFFFFF" 
      android:text="no" 
      /> 

     <RadioButton 
      android:id="@+id/rbYes" 
      style="@style/RadioButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#FFFFFF" 
      android:text="yes" /> 
+0

레이아웃 xml 파일을 붙여 넣으시겠습니까? 이 라디오 버튼으로 무엇을 할 것인가? – appukrb

+0

radiogroup 안에 라디오 버튼을 넣으십시오 ... – appukrb

답변

1

, 당신은 다른 버튼을 누르면 버튼은

, 당신이 두 버튼을 전환 할 것을 전환. 따라서 onCheckedChanged은 처음 라디오 버튼 중 하나를 누르면 한 번 확인되고 다음 번에는 두 번 확인됩니다.

http://developer.android.com/guide/topics/ui/controls/radiobutton.html

public void onRadioButtonClicked(View view) { 
    // Is the button now checked? 
    boolean checked = ((RadioButton) view).isChecked(); 

    // Check which radio button was clicked 
    switch(view.getId()) { 
     case R.id.radio_pirates: 
     if (checked) 
      // Do all things here for this button 
     break; 
     case R.id.radio_ninjas: 
     if (checked) 
      // Do all things here for this button 
     break; 
} 

에서 촬영 그냥 버튼이 선택된 경우에 원하는 일을.

+0

그래서 해결책은 무엇입니까? –

+0

편집 확인 ... – Zyber

+0

대단히 감사합니다. –

관련 문제