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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:52:35+00:00 2026-05-23T06:52:35+00:00

I have an application where i used Gallery widget to show a bunch of

  • 0

I have an application where i used Gallery widget to show a bunch of images present within drawable in a srcoll manner.

likes this below,

public class GalleryActivity extends Activity {
    private ImageView imageView;
    private int[] mImageIds = {
            R.drawable.restro1,
            R.drawable.restro2,
            R.drawable.restro3,
            R.drawable.restro4,
            R.drawable.restro5,
            R.drawable.restro6,
            R.drawable.restro7,
            R.drawable.restro8,
            R.drawable.restro9,
            R.drawable.restro10,
            R.drawable.restro11,
            R.drawable.restro12,
            R.drawable.restro13,
            R.drawable.restro14,
            R.drawable.restro15,
            R.drawable.restro16,
            R.drawable.restro17,
            R.drawable.restro18,
            R.drawable.restro19,
            R.drawable.restro20
    };


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Gallery g = (Gallery) findViewById(R.id.gallery);
        g.setAdapter(new ImageAdapter(this));

        imageView = (ImageView)findViewById(R.id.ImageView01);
        g.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                Toast.makeText(GalleryActivity.this, "" + (arg2+1), Toast.LENGTH_SHORT).show();
                imageView.setImageResource(mImageIds[arg2]);
            }
        });

    }


    public class ImageAdapter extends BaseAdapter {
        int mGalleryItemBackground;
        private Context mContext;



        public ImageAdapter(Context c) {
            mContext = c;
            TypedArray a = obtainStyledAttributes(R.styleable.Gallery2);//obtainStyledAttributes(android.R.style.Theme);
            mGalleryItemBackground = a.getResourceId(R.styleable.Gallery2_android_galleryItemBackground,1);
            a.recycle();
        }

        public int getCount() {
            return mImageIds.length;
        }

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

            i.setImageResource(mImageIds[position]);
            i.setLayoutParams(new Gallery.LayoutParams(350, 250));
            i.setScaleType(ImageView.ScaleType.FIT_XY);
            i.setBackgroundResource(mGalleryItemBackground);

            return i;
        }
    }
}

I got also o/p as i need. But my question is here the images are present in drawable so its easy. but i want to fetch images at runtime from server(json) in form of JSon array.
At that time what i should write instead of that Integer array mImageIds.
I converted that json array to string array(consists of a no of image urls)
after that what i send to that ImageAdapter class so it work properly.

Thank you

  • 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-23T06:52:36+00:00Added an answer on May 23, 2026 at 6:52 am

    Use ArrayList instead of array to load data dynamically, to set image from a path use imageView.setImageURI(Uri.parse("myimagepath"));

    Modify the following lines in your code as given below

    ArrayList<String> mImageIds = new ArrayList<String>();
    

    Add image urls after parsing from json at run time

    mImageIds.add("imageurl1");
    mImageIds.add("imageurl2");
    .....
    

    Instead of imageView.setImageResource(mImageIds[arg2]); inside setOnItemClickListener use the following

    imageView.setImageURI(Uri.parse(mImageIds.get(arg2)));
    

    Thanks
    Deepak

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

Sidebar

Related Questions

I have an application that used Macro. In this macro I would like to
Currently I have an application used to update my software, this is a standalone
i have application first this application is used by customer in demo mode and
Say I have an application that used an ORM (I am thinking of nHibernate
I see an application have used Log.info = some info where are these logs
I have an application that is used on several hundred computers across the company
We have an older VB6 application that used to run under various user's accounts.
I have a C# application that is used by about a dozen employees simultaneously.
I have an application that was originally written in Borland C++ and used a
I have an application where the System.Windows.Forms.ColorDialog dialog box is used as a color

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.