クイズアプリを作っています。
Fragment上にラジオボタンを置き、選択して判定ボタンを押すと判定結果が出力されます。
そして、次の問題に移行する際、問題や選択肢等が切り替わるのでラジオボタンの選択状態をリセットしたいと考えています。
ラジオボタンの非選択状態にする方法に関して調べてみたところ、Activity上のラジオボタンに関してのサイトは数多くありますが、Fragment上のラジオボタンに関するものがなかなか見つけられません。
知っている方いれば教えて頂きたいです。
java
1public class meanFragment extends Fragment { 2 /* 意味クイズのFragment */ 3 4 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 5 6 /* 中略 */ 7 8 final RadioButton button1 = (RadioButton) layout.findViewById(R.id.RadioButton1); 9 button1.setText((meaning.get(0)).get(1)); 10 final RadioButton button2 = (RadioButton) layout.findViewById(R.id.RadioButton2); 11 button2.setText((meaning.get(1)).get(1)); 12 final RadioButton button3 = (RadioButton) layout.findViewById(R.id.RadioButton3); 13 button3.setText((meaning.get(2)).get(1)); 14 final RadioButton button4 = (RadioButton) layout.findViewById(R.id.RadioButton4); 15 button4.setText((meaning.get(3)).get(1)); 16 17 final RadioGroup rg = (RadioGroup) layout.findViewById(R.id.RadioGroup); 18 rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 19 @Override 20 public void onCheckedChanged(RadioGroup radioGroup, final int id) { 21 radio = (RadioButton)radioGroup.findViewById(id); 22 } 23 }); 24 25 //正誤判定する ⇒ 略 */ 26 27 //次の問題に進む 28 next.setOnClickListener(new View.OnClickListener() { 29 @Override 30 public void onClick(View view){ 31 radio.clearSelection(); /*この部分。ActivityだとaddActionListenerでよいと書いてありました*/ 32 33 /* 中略 */ 34 35 button1.setText((meaning.get(0)).get(1)); 36 button2.setText((meaning.get(1)).get(1)); 37 button3.setText((meaning.get(2)).get(1)); 38 button4.setText((meaning.get(3)).get(1)); 39 } 40 }); 41 return layout; 42 } 43}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/22 06:47 編集
2016/11/22 06:53
2016/11/22 07:10