Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:23:24+00:00 2026-05-28T13:23:24+00:00

I have seen the API demos of android (/ApiDemos/src/com/example/android/apis/view/Gallery1.java) , but they take images

  • 0

I have seen the API demos of android (/ApiDemos/src/com/example/android/apis/view/Gallery1.java) , but they take images from the res folder within the project. I want to create a gallery of the images which are put up in the folder: /mnt/sdcard/Android/data/com.myapp/files/Pictures/

All i could come up was this code, which, i suppose, displays all images.

public class ExistingPicGallery extends Activity {

private Cursor cursor;
private int columnIndex;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery1);
    Gallery g=(Gallery)findViewById(R.id.gallery1);
    String[] projection = {MediaStore.Images.ImageColumns._ID,MediaStore.Images.Thumbnails.IMAGE_ID, 
            MediaStore.Images.Thumbnails.KIND};
    // Create the cursor pointing to the SDCard
    String selection = MediaStore.Images.Thumbnails.KIND +
            "="  + // Select only mini's 
                            MediaStore.Images.Thumbnails.MINI_KIND; 
    cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
            projection, 
            selection,
            null,
            null);
    // Get the column index of the image ID
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
    g.setAdapter(new ImageAdapter(this));

    g.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            Toast.makeText(ExistingPicGallery.this, "" + position, Toast.LENGTH_SHORT).show();
        }
    });

}



 public class ImageAdapter extends BaseAdapter {

     int mGalleryItemBackground;

      public ImageAdapter(Context c) {
            context = c;

            TypedArray a = obtainStyledAttributes(R.styleable.ExistingPicGallery);
            mGalleryItemBackground = a.getResourceId(
                    R.styleable.ExistingPicGallery_android_galleryItemBackground, 0);
            a.recycle();
        }

        public int getCount() {
            return cursor.getCount();
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(context);
            // Move cursor to current position
            cursor.moveToPosition(position);
            // Get the current value for the requested column
            int imageID = cursor.getInt(columnIndex);
            // obtain the image URI
            Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
            String url = uri.toString();
            // Set the content of the image based on the image URI
            int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
            Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
                            originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
            i.setImageBitmap(b);
            i.setLayoutParams(new Gallery.LayoutParams(150, 100));
            i.setScaleType(ImageView.ScaleType.FIT_XY);
            i.setBackgroundResource(0);
            return i;
        }

        private Context context;


        ;
    }
}

I have spent a lot of time looking for its solution, but no success..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:23:25+00:00Added an answer on May 28, 2026 at 1:23 pm

    I have made following changes in /ApiDemos/src/com/example/android/apis/view/Gallery1.java

    public class ImageAdapter extends BaseAdapter {
        int mGalleryItemBackground;
    
        public ImageAdapter(Context c) {
            mContext = c;
    
        }
    
        public int getCount() {
            return allFiles.length;
        }
    
        public Object getItem(int position) {
            return position;
        }
    
        public long getItemId(int position) {
            return position;
        }
    
        public View getView(final int position, View convertView,
                ViewGroup parent) {
    
            ImageView myImageView = new ImageView(mContext);
    
            if (convertView != null)
                myImageView = (ImageView) convertView;
            else {
                myImageView = new ImageView(mContext);
                myImageView.setLayoutParams(new GridView.LayoutParams(60, 60));
                myImageView.setAdjustViewBounds(false);
                myImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    
            }
    
            Bitmap bitmapImage = BitmapFactory.decodeFile(folder + "/"
                    + allFiles[position]);
            BitmapDrawable drawableImage = new BitmapDrawable(bitmapImage);
            myImageView.setImageDrawable(drawableImage);
    
            return myImageView;
    
        }
    
        private Context mContext;
    
        File folder = new File(
                Environment.getExternalStorageDirectory()
                .getPath()+"/files/Pictures/");
                String[] allFiles = folder.list();
    
    
    }
    

    Hence, we get array of image names in this folder. In the sample, we got the array of IDs of the drawables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any good CCK API docs out there? I have seen http://api.audean.com/ , but can't
I have seen the official demos on lwjgl.org but I would like to see
I have seen a lot of questions here regarding the Facebook Graph API but
Is there a twitter API that returns mood? I have seen some websites that
I have seen examples of printing from a windows application but I have not
I have seen simple example Ajax source codes in many online tutorials. What I
I have seen VS2010 exposing Network Emulator API. I have installed it and trying
I'm using the virtualbox api that uses COM on windows. If you have a
I have a image file stored at a remote server (i.e http://example.com/images).The images in
I have been searching on the Google Map API V3 documentation but I could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.