Custom adapter strange behavior - looping too many times
<p>I have a custom array adapter which is exhibiting unexpected behaviour when viewed in debug.</p>

<p>The code is below but the basics are:</p>

<ul>
<li>Custom array adapter being fed a list of 2 integers as List, support data of List and some other stuff.</li>
<li>Adapter inflates custom row xml which contains a TextView and a RadioGroup with 3 buttons in it.</li>
</ul>

<p>But this line creates some unexpected behaviour:</p>

<pre><code>holder.itemTitle.setText(result);
</code></pre>

<p>(and everything else) is getting hit 7 times for each integer in the array (in my test, just 2 integers)</p>

<p>So it will set the text for int[0], then set the text for int[1] and then do the same again 6 more times for each int.</p>

<p>Below is the pertinent parts of my adapter code:</p>

<pre><code>public class PainRecordFollowup_Adapter extends ArrayAdapter&lt;Integer&gt;{
    private final List&lt;Integer&gt; list;
    private final List&lt;LocationFollowup&gt; data;
    private final Integer LocationID;
    private final String Name;
    private final Integer Severity;
    private final Activity context;
    //this is the row background colours
    protected int[] colors = new int[] { 0x30ffffff, 0x30808080 };

    public PainRecordFollowup_Adapter(Activity context, List&lt;Integer&gt; list, List&lt;LocationFollowup&gt; data, Integer ID, String Name, Integer Severity) {
        super(context, R.layout.row_painrecord_followup, list);
        this.context = context;
        this.list = list;
        this.data = data;
        this.LocationID = ID;
        this.Name = Name;
        this.Severity = Severity;
    }

    static class ViewHolder {
        protected TextView itemTitle;
        protected RadioGroup rbGroup;
        protected RadioButton rbYes;
        protected RadioButton rbNo;
        protected RadioButton rbDK;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            LayoutInflater inflator = context.getLayoutInflater();
            view = inflator.inflate(R.layout.row_painrecord_followup, null);
            final ViewHolder viewHolder = new ViewHolder();
            viewHolder.itemTitle = (TextView) view.findViewById(R.id.tv_title);
            viewHolder.itemTitle.setPadding(0, 5, 0, 5);
            viewHolder.rbGroup = (RadioGroup) view.findViewById(R.id.rg_type);


            viewHolder.rbYes = (RadioButton) view.findViewById(R.id.rb_yes);
            viewHolder.rbNo = (RadioButton) view.findViewById(R.id.rb_no);
            viewHolder.rbDK = (RadioButton) view.findViewById(R.id.rb_dk);

            view.setTag(viewHolder);

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

        DataLayer d = new DataLayer(getContext());
        final String result = d.GetNameFromID(list.get(position));
        final String m_pos = list.get(position).toString();
        holder.itemTitle.setText(result);
        final int iYes, iNo, iDK;
        iYes = holder.rbYes.getId();
        iNo = holder.rbNo.getId();
        iDK = holder.rbDK.getId();

        //we need to loop through the data to see if there is
        //existing choices, and set the radio buttons accordingly
        Boolean isButtonMatch = false;
        Integer buttonValue = -1;
        if(data != null){
            if(data.size() &gt; 0){
              if(data.get(0).getReliefFollowup() != null){
                if(data.get(0).getReliefFollowup().size() &gt; 0){
                    for(int k=0; k&lt;data.get(0).getReliefFollowup().size(); k++){
                        if(data.get(0).getReliefFollowup().get(k).getID() == m_pos){
                            isButtonMatch = true;
                            buttonValue = data.get(0).getReliefFollowup().get(k).getValue();
                            break;
                        }
                    }

                    if(isButtonMatch){
                        if(buttonValue == 0){
                            holder.rbNo.setChecked(true);
                        }else if(buttonValue == 1){
                            holder.rbYes.setChecked(true);
                        }else if(buttonValue == 3){
                            holder.rbDK.setChecked(true);
                        }
                    }
                }
              }  
            }

        }

        //holder.rbNo.geti.setChecked(true);
        holder.rbGroup.setOnCheckedChangeListener(new android.widget.RadioGroup.OnCheckedChangeListener()
        {
// code continues...
</code></pre>

<p>And this is the call to the adapter from the Activity:</p>

<pre><code>reliefadapter = new PainRecordFollowup_Adapter(this,
             selectedIDs, pf_out.getLocationFollowup(), pd_in.getLocationDetails().get(mSelectedRow).getLocationID(),pd_in.getLocationDetails().get(mSelectedRow).getLocationName(),pd_in.getLocationDetails().get(mSelectedRow).getSeverity());
</code></pre>

<p>Any ideas why each item in the list is being hit 7 times? If it was 6 times I might have thought of a link between the 3 radio buttons per row plus some unknown modifier of 2, but 7? I would have expected it to be hit only once per list item.</p>

<p>LocationFollowUp is a Parcelable Class, if that helps any.</p>
