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 6619215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:56:17+00:00 2026-05-25T20:56:17+00:00

I am having images in SD card and from there i am able to

  • 0

I am having images in SD card and from there i am able to retrieve them and display them in my gallery.

Now i wanted to display the name of that particular image only using Toast.

Can any one tell me how can I do that???

My code is as follow

 package com.example.Gallery;

   import java.io.File;
   import java.util.ArrayList;
   import java.util.List;


   import android.app.Activity;
   import android.content.Context;
   import android.content.res.TypedArray;
   import android.graphics.Bitmap;
   import android.graphics.BitmapFactory;
   import android.os.Bundle;
   import android.os.Environment;
   import android.view.View;
   import android.view.ViewGroup;
   import android.widget.AdapterView;
   import android.widget.BaseAdapter;
   import android.widget.Gallery;
   import android.widget.ImageView;
   import android.widget.AdapterView.OnItemClickListener;
   import android.widget.TextView;
   import android.widget.Toast;

  public class HelloGallery extends Activity {
private TextView Text;
private List<String> ReadSDCard()
{
 List<String> tFileList = new ArrayList<String>();

 //It have to be matched with the directory in SDCard
 File f = new File("/sdcard/pictures/");
 File[] files=f.listFiles();
 if(files != null)//to check whether an image is present in that file or not
 {
     for(int i=0; i<files.length; i++)
     {
         File file = files[i];

         //to check the type of file and according allowing the files to display
         String curFile=file.getPath();
         String ext=curFile.substring(curFile.lastIndexOf(".")+1, 
                 curFile.length()).toLowerCase();
         if(ext.equals("jpg")||ext.equals("gif")||ext.equals("png"))
             /*It's assumed that all file in the path
                are in supported type*/

             tFileList.add(file.getPath());
     }
 }
 else
    {
        Text =(TextView)findViewById(R.id.text);
        Text.setText("THERE IS NO IMAGE IN THE cARD MOUNTED INTO DEVICE");
    }
    return tFileList;

}

   @Override
     public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     final ImageView imageView = (ImageView)findViewById(R.id.image1);

    Gallery g = (Gallery) findViewById(R.id.gallery);

   String state = Environment.getExternalStorageState();
    if (state.equals(Environment.MEDIA_MOUNTED)) 
    {
       final List<String> SD = ReadSDCard();
       g.setAdapter(new ImageAdapter(this, SD));

   //to saw image with image view
    g.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent,
      View v, int position, long id) {
     //to get a image file
     String imageInSD = SD.get(position);
     String imagename = imageInSD.intern();
     Toast.makeText(HelloGallery.this,
             imagename,
    Toast.LENGTH_SHORT).show();
      //to display image in image view
     Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
        imageView.setImageBitmap(bitmap);

    }
});
}
else
{
    Text =(TextView)findViewById(R.id.text);
    Text.setText("THERE IS NO EXTERNAL CARD MOUNTED IN THE DEVICE");
}

}

 public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private  List<String> FileList;

public ImageAdapter(Context c, List<String> fList) {
    mContext = c;
    FileList = fList;
    TypedArray a = obtainStyledAttributes(R.styleable.Theme);
    mGalleryItemBackground = a.getResourceId(
      R.styleable.Theme_android_galleryItemBackground,
      0);
    a.recycle();
}

public int getCount() {
    return FileList.size();
}

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(mContext);

    Bitmap bm = BitmapFactory.decodeFile(
      FileList.get(position).toString());
      i.setImageBitmap(bm);
      i.setLayoutParams(new Gallery.LayoutParams(150, 100));
      i.setScaleType(ImageView.ScaleType.FIT_XY);
      i.setBackgroundResource(mGalleryItemBackground);

    return i;
     }
 }

}

  • 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-25T20:56:18+00:00Added an answer on May 25, 2026 at 8:56 pm

    you should use this code to open gallery:

    Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent,"SelectPicture"),50);
    

    After selecting image from gallery ,control goes to OnActivityResult.

    then add this code to OnActivityResult:

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (resultCode == RESULT_OK) {
                if (requestCode == 50) {
                    Uri selectedImageUri = data.getData();
                  String  selectedImagePath = getPath(selectedImageUri);
    
                          Toast.makeText(this,selectedImagePath,Toast.LENGTH_LONG).show();
    }
    }
    }
    

    i hope this help you

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

Sidebar

Related Questions

I'm having some images from which the user should choose one. Now I don't
I am having a problem when I load images from my SD card and
I am having trouble with hiding/removing the card owner and image from the card
I'm retriving contacts from WP7. Some contacts having images some not having. I want
I'm using JS to animate two images by having them toggle on and off.
I am having 3 images. How can I access each one of them and
My application is having images sent to it from mobile devices with the content-type
I'm currently having a standard image selection (from the SD card) dialog shown when
Basically I had a grid view that showed a set of images from the
I'm having an odd problem on saving my bitmap image that I got from

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.