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

  • Home
  • SEARCH
  • 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 8119351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:46:48+00:00 2026-06-06T04:46:48+00:00

I had developed an application in which I have to display images from specific

  • 0

I had developed an application in which I have to display images from specific folder in sd card. My code is working fine but it is showing all images that are sd card. I had given selection args as my folder’s name as it has been metioned the following post:
Displaying images from a specific folder on the SDCard using a gridview

But, it didn’t worked. Please, suggest me how to do this:
Below I am posting my code.

public class Album1Activity extends Activity {
static Cursor imageCursor;
static int columnIndex;
GridView gridView;
Intent in;
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.grid);
    String[] imgColumnID = {MediaStore.Images.Thumbnails._ID};
    Uri uri = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;
    imageCursor = managedQuery(uri, imgColumnID, null, null, 
                    MediaStore.Images.Thumbnails.IMAGE_ID);
    columnIndex = imageCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
    gridView = (GridView)findViewById(R.id.gridview);
    gridView.setAdapter(new ImageAdapter(getApplicationContext()));
    gridView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position,
                long id) {
            String[] dataLocation = {MediaStore.Images.Media.DATA};
            //String []dataLocation = {Environment.getExternalStorageDirectory().getAbsolutePath()};
            imageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
                        dataLocation, null, null, null);
            columnIndex = imageCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            imageCursor.moveToPosition(position);
            String imgPath = imageCursor.getString(columnIndex);
            in = new Intent(getApplicationContext(), FullScreen.class);
            in.putExtra("id", imgPath);
            startActivity(in);
        }//onItemClickListener
    });
}//onCreate

public static class ImageAdapter extends BaseAdapter{
    private Context context;
    //Album1Activity act = new Album1Activity();
    public ImageAdapter(Context context){
        this.context = context;
    }//ImageAdapter
    public int getCount() {
        // TODO Auto-generated method stub
        return imageCursor.getCount();
    }//getCount

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }//getItem

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }//getItemId

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView iv;
        if(convertView == null){
            iv = new ImageView(context);
            imageCursor.moveToPosition(position);
            int imageID = imageCursor.getInt(columnIndex);
            iv.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                            "" +imageID));
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setPadding(5, 5, 5, 5);
            iv.setLayoutParams(new GridView.LayoutParams(100, 100));
        }//if
        else{
            iv = (ImageView)convertView;
        }//else
        return iv;
    }//getView

}//ImageAdapter

}//Album1Activity

  • 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-06-06T04:46:50+00:00Added an answer on June 6, 2026 at 4:46 am

    Sorry for Answering late…
    Below I am posting the final solution

    public class Album3 extends Activity {
    File [] mediaFiles;
    File imageDir;
    static GridView gridView;
    ImageAdapter adapter;
    Intent in;
    ImageButton btncam;
    String name = null;
    ArrayList<Bitmap> bmpArray = new ArrayList<Bitmap>();
    ArrayList<String> fileName = new ArrayList<String>();
    public static final String TAG = "Album3Activity";
    
    public void onCreate(Bundle savedInstanceState) 
    {
        imageDir = new File(Environment.getExternalStorageDirectory().toString()+
                 "/diplomat");
        super.onCreate(savedInstanceState);
        if((imageDir.exists()))
        {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.grid);
            mediaFiles = imageDir.listFiles();
            //Log.d("Length of images",""+mediaFiles.length);
            for(File file : mediaFiles)
            {
                bmpArray.add(convertToBitmap(file));
                fileName.add(readFileName(file));
                //Log.d(TAG + "bmpArray Size", ""+bmpArray.size());
                //Log.d(TAG, "call to convertToBitmap");
            }//for
    
            adapter = new ImageAdapter(this, bmpArray, fileName);
            gridView = (GridView)findViewById(R.id.gridview);
            gridView.setAdapter(adapter);
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED
                    , Uri.parse(Environment.getExternalStorageDirectory().toString()+"/diplomat")));
    
            gridView.setOnItemClickListener(new OnItemClickListener() {
    
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {
                in = new Intent(getApplicationContext(), FullScreen.class);
                in.putExtra("id", position);
                startActivity(in);
            }
        });
        }//if
        else
        {
            setContentView(R.layout.no_media);
        }
    }//onCreate
    
    public static Bitmap convertToBitmap(File file) 
    {
        URL url = null;
        try 
        {
            url = file.toURL();
        } catch (MalformedURLException e1) 
        {
            //Log.d(TAG, e1.toString());
        }//catch
    
        Bitmap bmp = null;
        try
        {
           bmp = BitmapFactory.decodeStream(url.openStream());
           //bmp.recycle();
        }catch(Exception e)
        {
            //Log.d(TAG, "Exception: "+e.toString());
        }//catch
        return bmp;
    }//convertToBitmap
    
    public String readFileName(File file){
        String name = file.getName();
        return name;
    }//readFileName
    }//class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some source code which I had developed and later gave to another
I have developed an Adobe AIR application which users install and launch from my
I have upgraded my iPhone SDK from 3.1.2 to 4. The application which I
I had developed an application. I done 2 sets of layout which were default
I've developed an application which uses the Symfony 2 framework. The application code resides
I had to developed an application which will communicate with a Web service via
We have developed an application in C# .NET WPF Office which we are about
I have an MFC application developed in VS Studio 2008 which reads and writes
I had developed one website purely in HTML .I have my form with fields
My last employer had developed an elaborate system which sat on top of SVN

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.