-1

アプリを実行すると、必要以上のラジオボタンが表示されます。ラジオボタンは同じグループで繰り返されるようです。何が起こっているのかよくわかりません。これが私のカスタム ArrayAdapter です。ここの問題を知りたい

public class QuestionsListAdapter extends ArrayAdapter<QuestionProperties> {


List<QuestionProperties> list;



Context test;



public QuestionsListAdapter(Context context,  int resource, List<QuestionProperties> list2) {
    super(context,resource,list2);
    test = context;
    list =list2;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view;

    final RadioButton[] rB;
     RadioHolder  holder = new RadioHolder();
    view= convertView;

    LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
            RadioGroup.LayoutParams.WRAP_CONTENT,
            RadioGroup.LayoutParams.WRAP_CONTENT);

        if(view == null)
        {
            LayoutInflater inflator = ((Activity) test).getLayoutInflater();
           view = inflator.inflate(R.layout.question_list_row, null);


            holder.questionTV = (TextView) view.findViewById(R.id.qTextView);
            holder.radiogroup = (RadioGroup) view.findViewById(R.id.radio_group);
            view.setTag(holder);

        }
        else{
            //view = convertView;
            holder = (RadioHolder) view.getTag();
            }



        holder.questionTV.setText(String.valueOf(list.get(position).getQuestionNo())+"."+" " + list.get(position).getQuestion());

        rB=new RadioButton[list.get(position).possibleAns.length];

        for(int count = 0; count<(list.get(position).possibleAns.length);count++)
        {
             rB[count]= new RadioButton(test);

            rB[count].setId(count);
            rB[count].setText(list.get(position).possibleAns[count]);
            layoutParams.weight=1.0f;
            layoutParams.setMargins(15, 0, 5, 10);
            rB[count].setOnClickListener(new View.OnClickListener(){

                @Override
                public void onClick(View v) {

                    String a = String.valueOf(v.getId());
                    Toast.makeText(QActivity.context, "Radio Button "+ a,Toast.LENGTH_SHORT).show();    
                  }
            });
            holder.radiogroup.addView(rB[count],layoutParams);  

        }
        return view;
}



  static class RadioHolder {
        protected TextView questionTV;
        protected RadioGroup radiogroup;

    }
4

1 に答える 1