2013-04-19 4 views
0

나는 android에서 퀴즈 응용 프로그램을 작업 중입니다. 라디오 버튼으로 질문과 옵션을 표시해야합니다. 다음 버튼을 클릭하면 다음 질문과 옵션이 표시됩니다. 질문과 옵션을 표시 할 수 있지만 한 가지 문제가 발생합니다.안드로이드에서 다음 버튼을 클릭하면 라디오 버튼을 제거하는 방법은 무엇입니까?

첫 번째 질문과 그 옵션이 잘 표시됩니다. 다음 버튼을 클릭하면 다음 질문이 표시되지만 옵션의 경우 첫 번째 질문 옵션과 두 번째 질문 옵션이 라디오 버튼으로 표시됩니다. 다시 한 번 다음 버튼을 클릭하면 세 번째 질문과 함께 두 번째 옵션도 표시됩니다. 다음 버튼을 클릭하면 이전 질문의 라디오 버튼을 어떻게 제거 할 수 있습니까?

내 코드 :

main.xml에

<ScrollView 
     android:id="@+id/scrl" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/widgetnotes" 
     android:layout_margin="6dp" 
     android:background="#FFFFFF" 
     android:scrollbars="none" > 

     <RelativeLayout 
      android:id="@+id/rel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/tv_question" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textColor="#000000" /> 

      <LinearLayout 
       android:id="@+id/chklnlayout" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_below="@+id/tv_question" 
       android:orientation="vertical" > 
      </LinearLayout> 
     </RelativeLayout> 
    </ScrollView> 

Page.java 
{ 
------ 

//first question---- 
optionslayout = (LinearLayout) findViewById(R.id.chklnlayout); 

       tv.setText(question); 
       tv.setTextColor(Color.parseColor("#000000")); 

       RadioGroup radiogroup = (RadioGroup) new RadioGroup(Page.this); 

       optionslayout.addView(radiogroup); 

       for (int k = 0; k < arr.length; k++) { 
        RadioButton newRadioButton = new RadioButton(Page.this); 

        newRadioButton.setText(arr2.get(k)); 
        newRadioButton.setTextColor(Color.parseColor("#000000")); 

        radiogroup.addView(newRadioButton); 

       } 

//next click-- 

public void next(View v) 
{ 
    if (i < array.length - 1) { 
    i++; 


optionslayout = (LinearLayout) findViewById(R.id.chklnlayout); 



      tv.setText(question); 
      tv.setTextColor(Color.parseColor("#000000")); 

      RadioGroup radiogroup = (RadioGroup) new RadioGroup(Page.this); 

      optionslayout.addView(radiogroup); 



      for (int p = 0; p < nextarr.length; p++) { 
       RadioButton newRadioButton = new RadioButton(Page.this); 

       newRadioButton.setText(arr6.get(p)); 
       newRadioButton.setTextColor(Color.parseColor("#000000")); 



       radiogroup.addView(newRadioButton); 

      } 


} 

} 

나는 그것이 다음 질문의 옵션이 표시되지 않도록 보관 때 다음 클릭 동작에 optionslayout.removeAllViews(); 퍼팅 시도했지만. 이 문제를 도와주세요.

답변

1

그냥이 시도 :

설정 라디오 그룹으로

radioGroup.clearCheck(); 

및 라디오 버튼 등 :

.setChecked(false); 
+0

안녕 내가 또한 optionslayout.removeView (을 radioGroup)를 추가; – user1448108

관련 문제