0

what I am trying to do is display 8 images in one listview item, but the problem I seem to be having is that when I am displaying the images, the cell re-creation is displaying the wrong images in the wrong cell at times.

I am basically trying to replicate the instagram news page (follow page to be precise), see image below:

multiple image in one item, Instagram

Also see below a picture of the problem I am having:

image of problem

So as you can see, there are 11 items in the bottom list and 2 items in the top but the item at the top is showing 8 images, which has been taken from the bottom item.

If anyone has come across this before and knows a way to solve it I would appreciate it very much.

I can place code on here, but at the moment its too large, comment for anything specific and I will edit the question as best as I can.

Thanks

EDIT

One thing i should have said before is that the images are coming from the phone storage/custom database. Also the adapter code is quite large, please see below:

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if (convertView == null) {

        convertView = mInflater.inflate(R.layout.list_item, parent, false);
        holder = new ViewHolder();

        holder.txtName = (TextView) convertView
                .findViewById(R.id.textView1);
        holder.txtCount = (TextView) convertView
                .findViewById(R.id.item_count);
        holder.add_item_text = (TextView) convertView
                .findViewById(R.id.add_item_text);

        holder.image1 = (ImageView) convertView
                .findViewById(R.id.imageView1);
        holder.image2 = (ImageView) convertView
                .findViewById(R.id.imageView2);
        holder.image3 = (ImageView) convertView
                .findViewById(R.id.imageView3);
        holder.image4 = (ImageView) convertView
                .findViewById(R.id.imageView4);
        holder.image5 = (ImageView) convertView
                .findViewById(R.id.imageView5);
        holder.image6 = (ImageView) convertView
                .findViewById(R.id.imageView6);
        holder.image7 = (ImageView) convertView
                .findViewById(R.id.imageView7);
        holder.image8 = (ImageView) convertView
                .findViewById(R.id.imageView8);

        holder.image1Overlay = (RelativeLayout) convertView
                .findViewById(R.id.imageView1Overlay);
        holder.image2Overlay = (RelativeLayout) convertView
                .findViewById(R.id.imageView2Overlay);
        holder.image3Overlay = (RelativeLayout) convertView
                .findViewById(R.id.imageView3Overlay);
        holder.image4Overlay = (RelativeLayout) convertView
                .findViewById(R.id.imageView4Overlay);
        holder.image5Overlay = (RelativeLayout) convertView
                .findViewById(R.id.imageView5Overlay);
        holder.image6Overlay = (RelativeLayout) convertView
                .findViewById(R.id.imageView6Overlay);
        holder.image7Overlay = (RelativeLayout) convertView
                .findViewById(R.id.imageView7Overlay);
        holder.image8Overlay = (RelativeLayout) convertView
                .findViewById(R.id.imageView8Overlay);


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

    String count = "0";

    holder.txtName.setText(searchArrayList.get(position).getName());
    if (searchArrayList.get(position).getCount() != null) {
        count = String.valueOf(searchArrayList.get(position).getCount());
    }
    holder.txtCount.setText(count);

    holder.image1.setVisibility(View.GONE);
    holder.image2.setVisibility(View.GONE);
    holder.image3.setVisibility(View.GONE);
    holder.image4.setVisibility(View.GONE);
    holder.image5.setVisibility(View.GONE);
    holder.image6.setVisibility(View.GONE);
    holder.image7.setVisibility(View.GONE);
    holder.image8.setVisibility(View.GONE);

    holder.image1Overlay.setVisibility(View.GONE);
    holder.image2Overlay.setVisibility(View.GONE);
    holder.image3Overlay.setVisibility(View.GONE);
    holder.image4Overlay.setVisibility(View.GONE);
    holder.image5Overlay.setVisibility(View.GONE);
    holder.image6Overlay.setVisibility(View.GONE);
    holder.image7Overlay.setVisibility(View.GONE);
    holder.image8Overlay.setVisibility(View.GONE);

    holder.add_item_text.setVisibility(View.VISIBLE);

    if (!(searchArrayList.get(position).getCount() == null)) {
        if (searchArrayList.get(position).getCount().equals("0")) {
            holder.image1.setVisibility(View.GONE);
            holder.image2.setVisibility(View.GONE);
            holder.image3.setVisibility(View.GONE);
            holder.image4.setVisibility(View.GONE);
            holder.image5.setVisibility(View.GONE);
            holder.image6.setVisibility(View.GONE);
            holder.image7.setVisibility(View.GONE);
            holder.image8.setVisibility(View.GONE);

            holder.image1Overlay.setVisibility(View.GONE);
            holder.image2Overlay.setVisibility(View.GONE);
            holder.image3Overlay.setVisibility(View.GONE);
            holder.image4Overlay.setVisibility(View.GONE);
            holder.image5Overlay.setVisibility(View.GONE);
            holder.image6Overlay.setVisibility(View.GONE);
            holder.image7Overlay.setVisibility(View.GONE);
            holder.image8Overlay.setVisibility(View.GONE);

            holder.add_item_text.setVisibility(View.VISIBLE);

        } else {
            holder.image1.setVisibility(View.VISIBLE);
            holder.image2.setVisibility(View.VISIBLE);
            holder.image3.setVisibility(View.VISIBLE);
            holder.image4.setVisibility(View.VISIBLE);
            holder.image5.setVisibility(View.VISIBLE);
            holder.image6.setVisibility(View.VISIBLE);
            holder.image7.setVisibility(View.VISIBLE);
            holder.image8.setVisibility(View.VISIBLE);

            bitmapImage = null;

            MainDataSouce datasource = new MainDataSouce(con);
            final ArrayList<MainFragmetnArray> array = createArray
                    .getArrayData(datasource, searchArrayList.get(position)
                            .getName(), con.getResources()
                            .getDisplayMetrics().density, 100);

            int size = array.size();

            System.out.println("SWITCH SIZE >>>>> " + size);

            switch (size) {

            case 0:

                System.out.println("CASE 0");

                bitmapImage = null;

                holder.image1.setImageBitmap(bitmapImage);
                holder.image2.setImageBitmap(bitmapImage);
                holder.image3.setImageBitmap(bitmapImage);
                holder.image4.setImageBitmap(bitmapImage);
                holder.image5.setImageBitmap(bitmapImage);
                holder.image6.setImageBitmap(bitmapImage);
                holder.image7.setImageBitmap(bitmapImage);
                holder.image8.setImageBitmap(bitmapImage);

                holder.image1.setVisibility(View.GONE);
                holder.image2.setVisibility(View.GONE);
                holder.image3.setVisibility(View.GONE);
                holder.image4.setVisibility(View.GONE);
                holder.image5.setVisibility(View.GONE);
                holder.image6.setVisibility(View.GONE);
                holder.image7.setVisibility(View.GONE);
                holder.image8.setVisibility(View.GONE);

                holder.image1Overlay.setVisibility(View.GONE);
                holder.image2Overlay.setVisibility(View.GONE);
                holder.image3Overlay.setVisibility(View.GONE);
                holder.image4Overlay.setVisibility(View.GONE);
                holder.image5Overlay.setVisibility(View.GONE);
                holder.image6Overlay.setVisibility(View.GONE);
                holder.image7Overlay.setVisibility(View.GONE);
                holder.image8Overlay.setVisibility(View.GONE);

                holder.add_item_text.setVisibility(View.VISIBLE);

                break;

            case 1:

                System.out.println("CASE 1");

                holder.add_item_text.setVisibility(View.GONE);

                if (array.get(0).getImage().equalsIgnoreCase("text item")) {
                    holder.image1.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(0).getImage(),
                            holder.image1);
                }
                if (array.get(0).getGotIt().equals("true")) {
                    holder.image1Overlay.setVisibility(View.VISIBLE);
                }

                break;

            case 2:

                System.out.println("CASE 2");

                holder.add_item_text.setVisibility(View.GONE);

                if (array.get(0).getImage().equalsIgnoreCase("text item")) {
                    holder.image1.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(0).getImage(),
                            holder.image1);
                }

                if (array.get(1).getImage().equalsIgnoreCase("text item")) {
                    holder.image2.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(1).getImage(),
                            holder.image2);
                }

                if (array.get(0).getGotIt().equals("true")) {
                    holder.image1Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(1).getGotIt().equals("true")) {
                    holder.image2Overlay.setVisibility(View.VISIBLE);
                }

                // System.gc();

                break;

            case 3:

                System.out.println("CASE 3");

                holder.add_item_text.setVisibility(View.GONE);

                if (array.get(0).getImage().equalsIgnoreCase("text item")) {
                    holder.image1.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(0).getImage(),
                            holder.image1);
                }

                if (array.get(1).getImage().equalsIgnoreCase("text item")) {
                    holder.image2.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(1).getImage(),
                            holder.image2);
                }

                if (array.get(2).getImage().equalsIgnoreCase("text item")) {
                    holder.image3.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(2).getImage(),
                            holder.image3);
                }

                if (array.get(0).getGotIt().equals("true")) {
                    holder.image1Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(1).getGotIt().equals("true")) {
                    holder.image2Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(2).getGotIt().equals("true")) {
                    holder.image3Overlay.setVisibility(View.VISIBLE);
                }

                // System.gc();

                break;

            case 4:

                System.out.println("CASE 4");

                holder.add_item_text.setVisibility(View.GONE);

                if (array.get(0).getImage().equalsIgnoreCase("text item")) {
                    holder.image1.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(0).getImage(),
                            holder.image1);
                }

                if (array.get(1).getImage().equalsIgnoreCase("text item")) {
                    holder.image2.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(1).getImage(),
                            holder.image2);
                }

                if (array.get(2).getImage().equalsIgnoreCase("text item")) {
                    holder.image3.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(2).getImage(),
                            holder.image3);
                }

                if (array.get(3).getImage().equalsIgnoreCase("text item")) {
                    holder.image4.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(3).getImage(),
                            holder.image4);
                }

                if (array.get(0).getGotIt().equals("true")) {
                    holder.image1Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(1).getGotIt().equals("true")) {
                    holder.image2Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(2).getGotIt().equals("true")) {
                    holder.image3Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(3).getGotIt().equals("true")) {
                    holder.image4Overlay.setVisibility(View.VISIBLE);
                }

                // System.gc();

                break;
            case 5:

                System.out.println("CASE 5");

                holder.add_item_text.setVisibility(View.GONE);

                if (array.get(0).getImage().equalsIgnoreCase("text item")) {
                    holder.image1.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(0).getImage(),
                            holder.image1);
                }

                if (array.get(1).getImage().equalsIgnoreCase("text item")) {
                    holder.image2.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(1).getImage(),
                            holder.image2);
                }

                if (array.get(2).getImage().equalsIgnoreCase("text item")) {
                    holder.image3.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(2).getImage(),
                            holder.image3);
                }

                if (array.get(3).getImage().equalsIgnoreCase("text item")) {
                    holder.image4.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(3).getImage(),
                            holder.image4);
                }

                if (array.get(4).getImage().equalsIgnoreCase("text item")) {
                    holder.image5.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(4).getImage(),
                            holder.image5);
                }

                if (array.get(0).getGotIt().equals("true")) {
                    holder.image1Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(1).getGotIt().equals("true")) {
                    holder.image2Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(2).getGotIt().equals("true")) {
                    holder.image3Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(3).getGotIt().equals("true")) {
                    holder.image4Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(4).getGotIt().equals("true")) {
                    holder.image5Overlay.setVisibility(View.VISIBLE);
                }

                break;
            case 6:

                System.out.println("CASE 6");

                holder.add_item_text.setVisibility(View.GONE);

                if (array.get(0).getImage().equalsIgnoreCase("text item")) {
                    holder.image1.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(0).getImage(),
                            holder.image1);
                }

                if (array.get(1).getImage().equalsIgnoreCase("text item")) {
                    holder.image2.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(1).getImage(),
                            holder.image2);
                }

                if (array.get(2).getImage().equalsIgnoreCase("text item")) {
                    holder.image3.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(2).getImage(),
                            holder.image3);
                }

                if (array.get(3).getImage().equalsIgnoreCase("text item")) {
                    holder.image4.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(3).getImage(),
                            holder.image4);
                }

                if (array.get(4).getImage().equalsIgnoreCase("text item")) {
                    holder.image5.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(4).getImage(),
                            holder.image5);
                }

                if (array.get(5).getImage().equalsIgnoreCase("text item")) {
                    holder.image6.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(5).getImage(),
                            holder.image6);
                }

                if (array.get(0).getGotIt().equals("true")) {
                    holder.image1Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(1).getGotIt().equals("true")) {
                    holder.image2Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(2).getGotIt().equals("true")) {
                    holder.image3Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(3).getGotIt().equals("true")) {
                    holder.image4Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(4).getGotIt().equals("true")) {
                    holder.image5Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(5).getGotIt().equals("true")) {
                    holder.image6Overlay.setVisibility(View.VISIBLE);
                }

                // System.gc();

                break;
            case 7:

                System.out.println("CASE 7");

                holder.add_item_text.setVisibility(View.GONE);

                if (array.get(0).getImage().equalsIgnoreCase("text item")) {
                    holder.image1.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(0).getImage(),
                            holder.image1);
                }

                if (array.get(1).getImage().equalsIgnoreCase("text item")) {
                    holder.image2.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(1).getImage(),
                            holder.image2);
                }

                if (array.get(2).getImage().equalsIgnoreCase("text item")) {
                    holder.image3.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(2).getImage(),
                            holder.image3);
                }

                if (array.get(3).getImage().equalsIgnoreCase("text item")) {
                    holder.image4.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(3).getImage(),
                            holder.image4);
                }

                if (array.get(4).getImage().equalsIgnoreCase("text item")) {
                    holder.image5.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(4).getImage(),
                            holder.image5);
                }

                if (array.get(5).getImage().equalsIgnoreCase("text item")) {
                    holder.image6.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(5).getImage(),
                            holder.image6);
                }

                if (array.get(6).getImage().equalsIgnoreCase("text item")) {
                    holder.image7.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(6).getImage(),
                            holder.image7);
                }

                if (array.get(0).getGotIt().equals("true")) {
                    holder.image1Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(1).getGotIt().equals("true")) {
                    holder.image2Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(2).getGotIt().equals("true")) {
                    holder.image3Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(3).getGotIt().equals("true")) {
                    holder.image4Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(4).getGotIt().equals("true")) {
                    holder.image5Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(5).getGotIt().equals("true")) {
                    holder.image6Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(6).getGotIt().equals("true")) {
                    holder.image7Overlay.setVisibility(View.VISIBLE);
                }

                break;

            default:

                System.out.println("CASE DEFAULT");

                holder.add_item_text.setVisibility(View.GONE);

                if (array.get(0).getImage().equalsIgnoreCase("text item")) {
                    holder.image1.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(0).getImage(),
                            holder.image1);
                }

                if (array.get(1).getImage().equalsIgnoreCase("text item")) {
                    holder.image2.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(1).getImage(),
                            holder.image2);
                }

                if (array.get(2).getImage().equalsIgnoreCase("text item")) {
                    holder.image3.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(2).getImage(),
                            holder.image3);
                }

                if (array.get(3).getImage().equalsIgnoreCase("text item")) {
                    holder.image4.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(3).getImage(),
                            holder.image4);
                }

                if (array.get(4).getImage().equalsIgnoreCase("text item")) {
                    holder.image5.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(4).getImage(),
                            holder.image5);
                }

                if (array.get(5).getImage().equalsIgnoreCase("text item")) {
                    holder.image6.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(5).getImage(),
                            holder.image6);
                }

                if (array.get(6).getImage().equalsIgnoreCase("text item")) {
                    holder.image7.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(6).getImage(),
                            holder.image7);
                }

                if (array.get(7).getImage().equalsIgnoreCase("text item")) {
                    holder.image8.setImageResource(R.drawable.green);
                } else {
                    imageLoaderFile.DisplayImage(array.get(7).getImage(),
                            holder.image8);
                }

                if (array.get(0).getGotIt().equals("true")) {
                    holder.image1Overlay.setVisibility(View.VISIBLE);
                }
                if (array.get(1).getGotIt().equals("true")) {
                    holder.image2Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(2).getGotIt().equals("true")) {
                    holder.image3Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(3).getGotIt().equals("true")) {
                    holder.image4Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(4).getGotIt().equals("true")) {
                    holder.image5Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(5).getGotIt().equals("true")) {
                    holder.image6Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(6).getGotIt().equals("true")) {
                    holder.image7Overlay.setVisibility(View.VISIBLE);
                }

                if (array.get(7).getGotIt().equals("true")) {
                    holder.image8Overlay.setVisibility(View.VISIBLE);
                }

                break;
            }
        }
    }

    return convertView;
}

Thanks

4

0 回答 0