Q:

No good position of Images in BaseAdapter

I have a PullToRefresh ListView with 5 sections (each section is a item of the list), and each section has a number of photos. I have an BaseAdapter class which fills the 5 sections with the section photos. The problem is when the first time I load the listview, the photos don't appear correctly, but when I do scroll, then, the photos appear in the correct position. 
I use the BitmapFun code for loading the photos. 
I have:
private ArrayList<Pair<Integer, ArrayList<String>>> section_photos_url;

The first value is the section, and the second is an array of photos of each section.
The getView method :
public View getView(int position, View convertView, ViewGroup container) {

    if (position < 5) {

        ItemViewHolder viewHolder;

        // Si la vista de dicha posicion ha sido inflada
        if (view_array[position] == null) { 

            // Inflate the view
            LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            switch (section_photos_url.get(position).first) {
            case ConstantsTypeSection.SECTION1:
                view_array[position] = li.inflate(R.layout.timeline_section_today_trending, container, false);
                break;
            case ConstantsTypeSection.SECTION2:
                view_array[position] = li.inflate(R.layout.timeline_section_trendy_smiler, container, false);
                break;
            case ConstantsTypeSection.SECTION3:
                view_array[position] = li.inflate(R.layout.timeline_section_around_me, container, false);
                break;
            case ConstantsTypeSection.SECTION4:
                view_array[position] = li.inflate(R.layout.timeline_section_trending_hashtag, container, false);
                break;
            case ConstantsTypeSection.SECTION5:
                view_array[position] = li.inflate(R.layout.timeline_section_last_content, container, false);
                break;
            }

            viewHolder = new ItemViewHolder();

            viewHolder.sectionName = (TextView) view_array[position].findViewById(R.id.section_name);
            viewHolder.userName = (TextView) view_array[position].findViewById(R.id.user_name);
            viewHolder.hashTag = (TextView) view_array[position].findViewById(R.id.hash_tag_name);

            viewHolder.userImage = (ImageView) view_array[position].findViewById(R.id.user_photo);

            viewHolder.item1 = (RecyclingImageView) view_array[position].findViewById(R.id.item_1);
            viewHolder.item2 = (RecyclingImageView) view_array[position].findViewById(R.id.item_2);
            viewHolder.item3 = (RecyclingImageView) view_array[position].findViewById(R.id.item_3);
            viewHolder.item4 = (RecyclingImageView) view_array[position].findViewById(R.id.item_4);
            viewHolder.item5 = (RecyclingImageView) view_array[position].findViewById(R.id.item_5);
            viewHolder.item6 = (RecyclingImageView) view_array[position].findViewById(R.id.item_6);
            viewHolder.item7 = (RecyclingImageView) view_array[position].findViewById(R.id.item_7);
            viewHolder.photos_layout = (LinearLayout) view_array[position].findViewById(R.id.photo_section);

            view_array[position].setTag(viewHolder);
        } else {
            viewHolder =  (ItemViewHolder) view_array[position].getTag();
        }

        switch (section_photos_url.get(position).first) {
        case ConstantsTypeSection.SECTION1:
                 viewHolder.sectionName.setText(context.getResources().getString(R.string.today_trending_section));

          LinearLayout.LayoutParams lp = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,    LinearLayout.LayoutParams.WRAP_CONTENT);
        viewHolder.photos_layout.addView(getPhotoView(section_photos_url.get(0).second), lp);

            break;
        case ConstantsTypeSection.SECTION2:
            viewHolder.sectionName.setText(context.getResources().getString(R.string.trendy_smiler_section));

                          LinearLayout.LayoutParams lp = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,    LinearLayout.LayoutParams.WRAP_CONTENT);
        viewHolder.photos_layout.addView(getPhotoView(section_photos_url.get(1).second), lp);

            break;
        case ConstantsTypeSection.SECTION3:
            viewHolder.sectionName.setText(context.getResources().getString(R.string.around_me_section));

                          LinearLayout.LayoutParams lp = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,    LinearLayout.LayoutParams.WRAP_CONTENT);
        viewHolder.photos_layout.addView(getPhotoView(section_photos_url.get(2).second), lp);
            break;
        case ConstantsTypeSection.SECTION4:
            viewHolder.sectionName.setText(context.getResources().getString(R.string.trending_hashtag_section));

                          LinearLayout.LayoutParams lp = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,    LinearLayout.LayoutParams.WRAP_CONTENT);
        viewHolder.photos_layout.addView(getPhotoView(section_photos_url.get(3).second), lp);
            break;
        case ConstantsTypeSection.SECTION5:
            viewHolder.sectionName.setText(context.getResources().getString(R.string.last_content_section));

                          LinearLayout.LayoutParams lp = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,    LinearLayout.LayoutParams.WRAP_CONTENT);
        viewHolder.photos_layout.addView(getPhotoView(section_photos_url.get(0).second), lp);
            break;
        }

        return view_array[position];

    } else {
        return null;
    }
}

private class ItemViewHolder {
    TextView sectionName;
    TextView userName;
    TextView hashTag;
    ImageView userImage;

    RecyclingImageView item1;
    RecyclingImageView item2;
    RecyclingImageView item3;
    RecyclingImageView item4;
    RecyclingImageView item5;
    RecyclingImageView item6;
    RecyclingImageView item7;

    LinearLayout photos_layout;

}

  private View getPhotoView(ArrayList<String> photos) {

    View view = null;

    LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    switch (photos.size()) {
    case 1:
        break;
    case 3:
        view = li.inflate(R.layout.timeline_item_three, null, false);
        break;
    case 5:
        if (Math.random() * 2 < 1) {
            view = li.inflate(R.layout.timeline_item_three_two, null, false);
        } else {
            view = li.inflate(R.layout.timeline_item_two_three, null, false);
        }
        break;
    case 7:
    default:
        view = li.inflate(R.layout.timeline_item_seven, null, false);
        break;
    }

    RecyclingImageView image = null;
    for (int i = 0; i < photos.size(); i++) {
        switch (i) {
        case 0:
              image =  (RecyclingImageView) view.findViewById(R.id.item_1);
            break;
        case 1:
            image =  (RecyclingImageView) view.findViewById(R.id.item_2);
            break;
        case 2:
            image =  (RecyclingImageView) view.findViewById(R.id.item_3);
            break;
        case 3:
            image =  (RecyclingImageView) view.findViewById(R.id.item_4);
            break;
        case 4:
            image =  (RecyclingImageView) view.findViewById(R.id.item_5);
            break;
        case 5:
            image =  (RecyclingImageView) view.findViewById(R.id.item_6);
            break;
        case 6:
            image =  (RecyclingImageView) view.findViewById(R.id.item_7);
            break;
        }

        CacheLoaderImagesSingleton.getInstance().getImageFetcher().loadImage(photos.get(i), image);
    }

    return view;
}

Any suggestions to show the images correctly? Those are the images. First one is the wrong images because all photos have to be purple flower photos, and don't yellow. Second one is the correct. The images are part of a section

A:

First, what is view_array if you are using that to store view at position in list. Then its wrong. The list is implemented to reuse views.
Second, for having different layouts for list view you use getItemViewType() and getViewTypeCount().
See example below,
public class Adapter extends BaseAdapter {

    private static final int SECTION1 = 0;
    private static final int SECTION2 = 1;
    private static final int SECTION3 = 2;
    private static final int SECTION4 = 3;
    private static final int SECTION5 = 4;

    ...

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

        View view;

        int type = getItemViewType(position);

        if (convertView == null)
        {
            switch (type) {
            case SECTION1:
                view = inflater.inflate(layout_id1, parent, false);
                break;
            case SECTION2:
                view = inflater.inflate(layout_id2, parent, false);
                break;
            case SECTION3:
                view = inflater.inflate(layout_id3, parent, false);
                break;
            case SECTION4:
                view = inflater.inflate(layout_id4, parent, false);
                break;
            case SECTION5:
                view = inflater.inflate(layout_id5, parent, false);
                break;
            }
        }
        else
        {
            // Based on value of getItemViewType the ListView will pass the 
            // corresponding layout which was inflated before by getView so no need to inflate again
            view = convertView;
        }

        ...

        return view;
    }

    // getItemViewType should return value from 0 to 4 since the count is 5
    // See doc for more info
    @Override
    public int getItemViewType(int position) {
        // return the section type which should be in range 0 to 4
    }

    @Override
    public int getViewTypeCount() {
        return 5;
    }
}

