0

i am doing an app loading currently taken images in the list view, I am able to load the images in the list view,but the problem is the images are repeatedly viewing in the list after 3 items and some tine its view then and there in the imageview.but my need is to add the image in the list when the user took,please help me thanks in advance. @Override public View getView(int position, View convertview, ViewGroup parent) { View vi = convertview;

    try {
        // TODO Auto-generated method stub

        ViewHolder holder;
        if (vi == null) {
            holder = new ViewHolder();

            vi = inflater.inflate(R.layout.my_trip_list_view_items, null);


            holder.place_name = (TextView) vi.findViewById(R.id.my_trip_list_view_place_name);

            holder.Day = (TextView) vi.findViewById(R.id.my_trip_list_view_date_time);
            holder.place_images = (ImageView) vi.findViewById(R.id.my_trip_list_view_Image_view);

            //*Note svg*//*
            holder. place_images.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
            menu_svg = SVGParser.getSVGFromResource(context.getResources(), R.raw.map_2);
            holder.place_images.setImageDrawable(menu_svg.createPictureDrawable());



            vi.setTag(holder);
        } else {
            holder = (ViewHolder) vi.getTag();
        }
        // images_view = new MyTrip_getmethod();
        String location_name = Location.get(position).toString();
        System.out.println("location_name>>>>>>>>>>>" + location_name);
        holder.place_name.setText(location_name);
        System.out.println("location_name>>>>>>>>>>>" + holder.place_name);

        holder.Day.setText(day.get(position).toString());
        System.out.println(" ### imgFile----" + image);

        holder.place_images.setImageBitmap(image.get(position));


        System.out.println("location_name>>im>>>>>>>>>>>" + holder.place_images);

        notifyDataSetChanged();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return vi;
}
hari
  • 11
  • 5

1 Answers1

1

This a problem with listview recycling issue.tO avoid this settag for your imageview with the position parameter of the getview method of your adapter class.

try {
        // TODO Auto-generated method stub
        int crnposition=position; 
        ViewHolder holder;
        if (vi == null) {
            holder = new ViewHolder();

            vi = inflater.inflate(R.layout.my_trip_list_view_items, null);


            holder.place_name = (TextView) vi.findViewById(R.id.my_trip_list_view_place_name);

            holder.Day = (TextView) vi.findViewById(R.id.my_trip_list_view_date_time);
            holder.place_images = (ImageView) vi.findViewById(R.id.my_trip_list_view_Image_view);

            //*Note svg*//*
            holder. place_images.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
            menu_svg = SVGParser.getSVGFromResource(context.getResources(), R.raw.map_2);
            holder.place_images.setImageDrawable(menu_svg.createPictureDrawable());



            vi.setTag(holder);
        } else {
            holder = (ViewHolder) vi.getTag();
        }
  holder.setTag(crntposition);
  holder.place_images.setTag(crntposition);
        // images_view = new MyTrip_getmethod();
        String location_name = Location.get(position).toString();
        System.out.println("location_name>>>>>>>>>>>" + location_name);
        holder.place_name.setText(location_name);
        System.out.println("location_name>>>>>>>>>>>" + holder.place_name);

        holder.Day.setText(day.get(position).toString());
        System.out.println(" ### imgFile----" + image);

        holder.place_images.setImageBitmap(image.get(Integer.parseInt(imageview.getTag().toString())));`


        System.out.println("location_name>>im>>>>>>>>>>>" + holder.place_images);

        notifyDataSetChanged();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return vi;
} 





and use like `holder.place_images.setImageBitmap(image.get(Integer.parseInt(holder.place_images.getTag().toString())));`
Karthika PB
  • 1,373
  • 9
  • 16
  • i am using the bitmap for imageview – hari Apr 02 '15 at 07:31
  • do you get that from an array please post your code so that someone can help you here... – Karthika PB Apr 02 '15 at 07:33
  • adapter = new MyTrip_listview_Adapter(MyTrip.this, location, Date_Array,imagesview, j, context, arrayplaces); listViewplace.setAdapter(adapter); the above is the adapter,here i have decleared in this location is viewed service every 5min holder.place_images.setImageBitmap(image.get(position)); – hari Apr 02 '15 at 07:54
  • @hari check my edits try to post your code in your question itself. – Karthika PB Apr 02 '15 at 08:32
  • i have given my getview method in my adapter class – hari Apr 02 '15 at 09:05
  • Thanks for your reply Like this only I have done, here my images itself is not loading and here i am using Array to get the images – hari Apr 02 '15 at 09:46
  • no issue ,But,images is not viewing in the list itself.Before i am able to get the images – hari Apr 02 '15 at 09:51
  • I don't know hat's happening there I usually use this way to meet listview issues like repetition.Sorry – Karthika PB Apr 02 '15 at 09:53
  • in your codes what is imageview refer to holder.place_images.setImageBitmap(image.get(Integer.parseInt(imageview.getTag().toString())));` – hari Apr 02 '15 at 09:58
  • oh sorry pls replace with holder.place_images – Karthika PB Apr 02 '15 at 10:19
  • while doing this the taken image is not viewing in the listview itself – hari Apr 02 '15 at 10:25
  • did you copy/pasted my code completely?please print the log for System.out.println("image" +image.get(Integer.parseInt(imageview.getTag().toString())) – Karthika PB Apr 02 '15 at 10:27