0

I have a Gallery activity that in the onCreate method is setting a file path for images to display like so:

      // Set up an array of the Thumbnail Image ID column we want
            String[] projection = {MediaStore.Images.Media._ID};
            // Create the cursor pointing to the SDCard
            cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    projection, // Which columns to return
                    MediaStore.Images.Media.DATA + " like ? ",
                    new String[] {"%LC/images%"},  
                    MediaStore.Images.Media._ID + " DESC");


            // Get the column index of the Thumbnails Image ID
            columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);


            ga.setAdapter(new GallAdapter(this,cursor,columnIndex));


public class GallAdapter extends BaseAdapter {
        public Cursor cursor;
        private int columnIndex;
        private Context context;
        int imageBackground;
        String url;
        Uri uri;
        int originalImageId;
        int imageID;
        int columnData;
        ViewGroup myp;
        ImageView d;

        public GallAdapter(Context ctx, Cursor cur, int cIn ) {
            context = ctx;
            columnIndex = cIn;

            cursor = cur;
        }

        @Override
        public int getCount() {

            return cursor.getCount();
        }

        @Override
        public Object getItem(int position) {

            return position;
        }

        @Override
        public long getItemId(int position) {

            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            myp = parent;
            View v;
            if(convertView ==null){
                v = LayoutInflater.from(context).inflate(R.layout.galitem, parent, false);
            }else{
                v = convertView;
            }


            ImageView photo = (ImageView) v.findViewById(R.id.imageView);
            ImageView border = (ImageView) v.findViewById(R.id.borderView);
            d = (ImageView) v.findViewById(R.id.delView);



            // Move cursor to current position
            cursor.moveToPosition(position);

            // Get the current value for the requested column
            imageID = cursor.getInt(columnIndex);
            // obtain the image URI
            uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
            url = uri.toString();
            // Set the content of the image based on the image URI
            originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
            Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(),
                            originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
            photo.setImageBitmap(b);

            photo.setScaleType(ImageView.ScaleType.FIT_CENTER); 
            d.setTag(uri);
            d.setOnClickListener(new OnClickListener(){


                public void onClick(View v) {

                    String path = getRealPathFromURI((Uri) v.getTag());
                    alertBox("Warning!", "Are you sure you want to delete this photo?", path, v);


                }


            });

            return v;
        }

    }

Problem is its not showing the most up to date images in the gallery sometimes it shows nothing or sometimes it shows old images that are not there any more

erik
  • 4,946
  • 13
  • 70
  • 120
  • Problem could be in `cursor` or `getView()`. Debug and see if the cursor is updated, if yes then `convertview` could be the culprit as it reuses the view.Also make sure you close the cursor in onDestroy – Sayyam Aug 16 '12 at 18:57
  • it use to work just fine and the tablet when through an update.. the folder i think used to be /sdcard/LC/images but now in file viewer its /Root/LC/images – erik Aug 16 '12 at 19:20
  • can you help me figure out how to point to the proper folder? – erik Aug 16 '12 at 19:20
  • To point to the folder you can use this code: `String path = cursor .getString(galleryCursor.getColumnIndex(MediaStore.Image.Media.DATA));` path has the absolute path to the image file. – Sayyam Aug 16 '12 at 19:39
  • it really just seems that the sdcard is being cached.. ill get some old images from that folder that are not there anymore.. or only images that were there since last time i rebooted the tablet.. its f'd – erik Aug 16 '12 at 19:46

0 Answers0