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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:55:34+00:00 2026-05-24T01:55:34+00:00

I have a requirement in that I want to implement an image gallery with

  • 0

I have a requirement in that I want to implement an image gallery with a GridView.
I tried using Hello gallery on the Android developer website. But the GridView doesn’t work.

  • 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-24T01:55:35+00:00Added an answer on May 24, 2026 at 1:55 am

    Use this XML for Layout : gallery.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:background="@drawable/bg_child">
    
        <FrameLayout android:id="@+id/FrameLayout01"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <FrameLayout android:id="@+id/LinearLayout01"
                android:layout_gravity="top" android:layout_height="50dp" android:layout_width="fill_parent">
                <TextView android:id="@+id/TextView01"
                    android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:layout_gravity="center_vertical" android:layout_marginLeft="30dp" android:gravity="center_vertical" android:drawableLeft="@drawable/photo_frame" android:textColor="@color/grey" android:text="@string/photogallery_txt"></TextView>
                <Button android:layout_gravity="right" android:id="@+id/btnMoreInfo" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:textStyle="bold" android:background="@drawable/my_child_button" android:layout_width="100dp" android:layout_height="40dp" android:text="@string/moreinfo_txt"></Button>
            </FrameLayout>
            <GridView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/gridview" android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:columnWidth="90dp"
                android:numColumns="auto_fit" android:verticalSpacing="10dp"
                android:horizontalSpacing="10dp" android:stretchMode="columnWidth"
                android:gravity="center" android:layout_gravity="bottom"
                android:layout_marginTop="50dp"></GridView>
        </FrameLayout>
    </LinearLayout>
    

    Activity File GalleryPage.java

    public class GalleryPage extends Activity {
    
        // private Integer[] mImageIds = {R.drawable.splash, R.drawable.splash,
        // R.drawable.splash, R.drawable.splash, R.drawable.splash,
        // R.drawable.splash, R.drawable.splash};
    
        private static Uri[] mUrls = null;
        private static String[] strUrls = null;
        private String[] mNames = null;
        private GridView gridview = null;
        private Cursor cc = null;
        private Button btnMoreInfo = null;
        private ProgressDialog myProgressDialog = null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
    
            CommonFunctions.setLanguage(getBaseContext());
    
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.gallery);
            btnMoreInfo = (Button) findViewById(R.id.btnMoreInfo);
            // It have to be matched with the directory in SDCard
            cc = this.getContentResolver().query(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null,
                    null);
    
            // File[] files=f.listFiles();
            if (cc != null) {
    
                myProgressDialog = new ProgressDialog(GalleryPage.this);
                myProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                myProgressDialog.setMessage(getResources().getString(R.string.pls_wait_txt));
                //myProgressDialog.setIcon(R.drawable.blind);
                myProgressDialog.show();
    
                new Thread() {
                    public void run() {
                        try {
                            cc.moveToFirst();
                            mUrls = new Uri[cc.getCount()];
                            strUrls = new String[cc.getCount()];
                            mNames = new String[cc.getCount()];
                            for (int i = 0; i < cc.getCount(); i++) {
                                cc.moveToPosition(i);
                                mUrls[i] = Uri.parse(cc.getString(1));
                                strUrls[i] = cc.getString(1);
                                mNames[i] = cc.getString(3);
                                //Log.e("mNames[i]",mNames[i]+":"+cc.getColumnCount()+ " : " +cc.getString(3));
                            }
    
                        } catch (Exception e) {
                        }
                        myProgressDialog.dismiss();
                    }
                }.start();
             gridview = (GridView) findViewById(R.id.gridview);
             gridview.setAdapter(new ImageAdapter(this));
    
             gridview.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View v,
                      int position, long id) {
                   Intent i = new Intent(GalleryPage.this, BigImage.class);
                   Log.e("intent : ", ""+position);
                   i.putExtra("imgUrls", strUrls);
                   i.putExtra("position", position);
                   startActivity(i);
                }
             });
    
            }
    
            btnMoreInfo.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i = new Intent(GalleryPage.this, ChildLogin.class);
                    startActivity(i);
                }
            });
        }
    
        /**
         * This class loads the image gallery in grid view.
         *
         */
        public class ImageAdapter extends BaseAdapter {
            private Context mContext;
    
            public ImageAdapter(Context c) {
                mContext = c;
            }
    
            public int getCount() {
                return cc.getCount();
            }
    
            public Object getItem(int position) {
                return null;
            }
    
            public long getItemId(int position) {
                return 0;
            }
    
            // create a new ImageView for each item referenced by the Adapter
            public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.galchild, null);
    
                try {
    
                    ImageView imageView = (ImageView) v.findViewById(R.id.ImageView01);
                    //imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                    // imageView.setPadding(8, 8, 8, 8);
                    Bitmap bmp = decodeURI(mUrls[position].getPath());
                    //BitmapFactory.decodeFile(mUrls[position].getPath());
                    imageView.setImageBitmap(bmp);
                    //bmp.
                    TextView txtName = (TextView) v.findViewById(R.id.TextView01);
                    txtName.setText(mNames[position]);
                } catch (Exception e) {
    
                }
                return v;
            }
        }
    
        @Override
        protected void onStart() {
            // TODO Auto-generated method stub
            super.onStart();
            FlurryAgent.onStartSession(this, "***");
        }
        // @Override
        // protected void onStop() {
        // TODO Auto-generated method stub
        // super.onStop();
        // FlurryAgent.onEndSession(this);
    
        // }
    
        /**
         * This method is to scale down the image 
         */
        public Bitmap decodeURI(String filePath){
    
            Options options = new Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(filePath, options);
    
            // Only scale if we need to 
            // (16384 buffer for img processing)
            Boolean scaleByHeight = Math.abs(options.outHeight - 100) >= Math.abs(options.outWidth - 100);
            if(options.outHeight * options.outWidth * 2 >= 16384){
                // Load, scaling to smallest power of 2 that'll get it <= desired dimensions
                double sampleSize = scaleByHeight
                    ? options.outHeight / 100
                    : options.outWidth / 100;
                options.inSampleSize = 
                    (int)Math.pow(2d, Math.floor(
                    Math.log(sampleSize)/Math.log(2d)));
            }
    
            // Do the actual decoding
            options.inJustDecodeBounds = false;
            options.inTempStorage = new byte[512];  
            Bitmap output = BitmapFactory.decodeFile(filePath, options);
    
            return output;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement that I want to check the request headers and according
I have a requirement that i want to get all the system services running
My requirement is that I want an object (tee) to update if there have
I have a requirement that I need to show my records in a gridview
I have a client who's requirement is that he wants a website which would
Hi I am using CAS for SSO. But problem is that i want reset
In our project we have requirement that, after receiving sms message from third party
I have the requirement that I need to open a document in Microsoft word
I have a requirement that when the user clicks on [X] button of the
I have a requirement that a user is allowed only to enter string value

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.