###前提・実現したいこと
アンケート機能をアプリでつくっています。
アンケート内容は、WebAPIからうけとります。
質問数、質問に対する回答の数は不定です。
質問にたいする回答は、RadioButtonで選択させるようにしようと考えています。
###発生している問題・エラーメッセージ
当初、RadioButtonのxmlを作成し、
inflaterから呼び出して、
WebAPIに含まれていた回答数の分だけ、
RadioGroupに対してaddView()したのですが、
複数選択できてしまったりと、RadioGroupが正しく動作しません。
addViewしたあと、初期化などしなければならなかったりするのでしょうか。。。
なお、XMLで定義せずに、new RadioButton(Context)で新たに定義した場合には、
正しく動作しています。
しかし、RadioButtonに対してボタン部分を変更するstyleを当てたいので、
このやり方では厳しいかなとかんがえています。
###ソースコード
RadioGroupAdapter.java
java
1@Override 2public function getView(final int position, View convertView, ViewGroup parent) { 3~~~~~~~~~~~~~~~~~~~~~~~~~~ 4略 5~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 7 // RadioGroupに質問項目をいれていく 8 RadioGroup g = (RadioGroup) convertView.findViewById(R.id.list_radio_group); 9 g.setTag(item); 10 for (int i = 0; i < choices.size(); i++) { 11 RadioButton r = inflater.inflate(R.layout.radio_button, null); 12 r.setTextColor(Color.parseColor("#505050")); 13 r.setText(choices.get(i).choice); 14 r.setTag(choices.get(i)); 15 r.setBackgroundResource(R.drawable.radio_shape); 16 17 g.addView(r); 18 } 19 20~~~~~~~~~~~~~~~~~~~~~~~~~~ 21略 22~~~~~~~~~~~~~~~~~~~~~~~~~~ 23
xml
1<?xml version="1.0" encoding="utf-8"?> 2<RadioButton 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 android:id="@+id/list_radio" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:background="@drawable/radio_shape" 8 android:textColor="#222" 9 android:layout_marginBottom="5dp" 10 />
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/16 09:30