0
我正在研究android中的測驗應用程序。我需要用單選按鈕顯示問題及其選項。當下一個按鈕被點擊下一個問題時,它的選項將被顯示。我能夠顯示問題和選項,但我遇到了一個問題。如何在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();
在明年的點擊動作,但是當我把它不會顯示下一題的選項。請幫我解決這個問題。
嗨,我還加optionslayout.removeView(RadioGroup中); – user1448108